Documentation Git and GitHub Basics | THH Study Jams

4 min read 2 hours ago
Published on Jan 31, 2025 This response is partially generated with the help of AI. It may contain inaccuracies.

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.

  1. Download Git

    • Visit the official Git website at git-scm.com.
    • Click on the download link for your operating system (Windows, macOS, or Linux).
  2. 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.
  3. 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.

  1. Set Your Name

    • Run the command:
      git config --global user.name "Your Name"
      
  2. Set Your Email

    • Run the command:
      git config --global user.email "your.email@example.com"
      
  3. Check Configuration

    • To verify your settings, run:
      git config --list
      

Step 3: Create a GitHub Account

GitHub is a platform for hosting Git repositories.

  1. Sign Up

    • Go to github.com and click on "Sign up."
    • Fill in your details and create your account.
  2. 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.

  1. New Repository

    • Click the "+" icon in the top right corner and select "New repository."
    • Choose a name for your repository and add a description.
  2. Initialize Repository

    • Decide if you want to initialize it with a README file. This is useful for providing information about your project.
  3. 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.

  1. Copy Repository URL

    • On your GitHub repository page, click the green "Code" button and copy the URL.
  2. Clone Command

    • Open your terminal and run:
      git clone <repository-url>
      
    • Replace <repository-url> with the URL you copied.

Step 6: Make Changes and Commit

After cloning, you can start making changes to your files.

  1. Navigate to Repository Folder

    • Use the cd command to navigate into your cloned repository:
      cd <repository-name>
      
  2. Edit Files

    • Make changes using your preferred text editor.
  3. Stage Changes

    • Add files to the staging area with:
      git add <filename>
      
    • To stage all changes, use:
      git add .
      
  4. Commit Changes

    • Commit your changes with a message:
      git commit -m "Your commit message"
      

Step 7: Push Changes to GitHub

To update your GitHub repository with local changes, push your commits.

  1. Push Command
    • Run the following command:
      git push origin main
      
    • Replace main with your branch name if different.

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!