Documentation Git and GitHub Basics | THH Study Jams
Table of Contents
Introduction
This tutorial covers the basics of using Git and GitHub, essential tools for version control and collaboration in software development. Understanding these tools allows you to manage code changes effectively, collaborate with others, and maintain a history of your projects.
Step 1: Install Git
To start using Git, you need to install it on your machine.
-
Download Git
- Visit the official Git website at git-scm.com.
- Click on the download link for your operating system (Windows, macOS, or Linux).
-
Install Git
- Follow the installation instructions specific to your operating system.
- For Windows, ensure to select the option to use Git from the Windows Command Prompt.
-
Verify Installation
- Open your terminal or command prompt.
- Type
git --version
and press Enter. You should see the installed version of Git.
Step 2: Configure Git
After installing Git, configure your user information.
-
Set Your Name
- Run the command:
git config --global user.name "Your Name"
- Run the command:
-
Set Your Email
- Run the command:
git config --global user.email "your.email@example.com"
- Run the command:
-
Check Configuration
- To verify your settings, run:
git config --list
- To verify your settings, run:
Step 3: Create a GitHub Account
GitHub is a platform for hosting Git repositories.
-
Sign Up
- Go to github.com and click on "Sign up."
- Fill in your details and create your account.
-
Set Up Your Profile
- After signing up, complete your profile to enhance collaboration opportunities.
Step 4: Create a New Repository on GitHub
A repository is where your project files will be stored.
-
New Repository
- Click the "+" icon in the top right corner and select "New repository."
- Choose a name for your repository and add a description.
-
Initialize Repository
- Decide if you want to initialize it with a README file. This is useful for providing information about your project.
-
Create Repository
- Click the "Create repository" button.
Step 5: Clone the Repository Locally
To work on your project, clone the repository to your local machine.
-
Copy Repository URL
- On your GitHub repository page, click the green "Code" button and copy the URL.
-
Clone Command
- Open your terminal and run:
git clone <repository-url>
- Replace
<repository-url>
with the URL you copied.
- Open your terminal and run:
Step 6: Make Changes and Commit
After cloning, you can start making changes to your files.
-
Navigate to Repository Folder
- Use the
cd
command to navigate into your cloned repository:cd <repository-name>
- Use the
-
Edit Files
- Make changes using your preferred text editor.
-
Stage Changes
- Add files to the staging area with:
git add <filename>
- To stage all changes, use:
git add .
- Add files to the staging area with:
-
Commit Changes
- Commit your changes with a message:
git commit -m "Your commit message"
- Commit your changes with a message:
Step 7: Push Changes to GitHub
To update your GitHub repository with local changes, push your commits.
- Push Command
- Run the following command:
git push origin main
- Replace
main
with your branch name if different.
- Run the following command:
Conclusion
You have now learned the basics of Git and GitHub, including installation, configuration, creating repositories, and managing code changes. To continue your learning, explore more advanced features such as branching, pull requests, and collaboration workflows. Start practicing these steps with your own projects to solidify your understanding. Happy coding!