Using GitHub with Git: A Beginner’s Guide

GitHub is a web-based platform that helps you collaborate on software projects using Git, a version control system. This guide will walk you through the basics of using GitHub and common Git commands. Let’s get started:

Step 1: Create a GitHub Account

  1. Go to GitHub and sign up for an account if you don’t already have one.

Step 2: Install Git

  1. Download and install Git on your computer from the official Git website. Follow the installation instructions for your operating system.

Step 3: Configure Git

  1. Open your terminal or command prompt and configure Git with your name and email:
   git config --global user.name "Your Name"
   git config --global user.email "[email protected]"

Step 4: Create a New Repository on GitHub

  1. Log in to your GitHub account and click the “+” icon in the upper right corner to create a new repository.
  • Choose a name for your repository.
  • Optionally, add a description.
  • Choose visibility (public or private).
  • Initialize the repository with a README file.
  • Click “Create repository.”

Step 5: Clone the Repository

  1. Clone the repository to your local machine using the following command:
   git clone https://github.com/your-username/your-repo.git

Step 6: Make Changes

  1. Create or edit files in your local repository. Use any text editor or integrated development environment (IDE) of your choice.

Step 7: Stage and Commit Changes

  1. Use Git to track your changes:
  • To see the status of your changes: git status
  • To stage changes for commit: git add filename or git add . to stage all changes.
  • To commit changes: git commit -m "Your commit message"

Step 8: Push Changes to GitHub

  1. Push your local changes to the remote GitHub repository:
   git push origin main

Replace “main” with the branch name if you are working with a different branch.

Step 9: Pull Changes from GitHub

  1. If others have made changes to the repository, you can pull their changes to your local repository:
   git pull origin main

Step 10: Branching

  1. Create a new branch to work on a specific feature or fix:
    • Create a new branch: git checkout -b new-branch-name
    • Make changes and commit as usual.
    • Push the new branch to GitHub: git push origin new-branch-name

Step 11: Pull Requests

  1. When you’re ready to merge your changes into the main branch, create a pull request on GitHub:
    • Go to your repository on GitHub.
    • Click “New pull request.”
    • Compare the changes, add a description, and create the pull request.

Step 12: Merge Changes

  1. Reviewers can comment on your pull request, and when everything is approved, you can merge the changes into the main branch.

These are the basic steps for using GitHub with Git. As you become more familiar with Git and GitHub, you can explore more advanced features and workflows like branching strategies, code reviews, and issue tracking to streamline your collaboration with others.

Hello, I’m Anuj. I make and teach software.

My website is free of advertisements, affiliate links, tracking or analytics, sponsored posts, and paywalls.
Follow me on LinkedIn, X (twitter) to get timely updates when I post new articles.
My students are the reason this website exists. ❤️

Feedback Display