Complete Git & GitHub Guide (2026)

By YusufMTech

Lesson 1: What is Git?

Git is a distributed version control system designed to track changes in your code over time. Before Git, developers often saved multiple copies of files with confusing names like project-final.html, project-final2.html, etc. Git solves this by keeping a full history of your project, allowing you to revert to previous versions easily.

Created in 2005 by Linus Torvalds, Git handles large projects efficiently and safely. Developers worldwide use it to manage websites, software, and apps.

Benefits of learning Git include:

Lesson 2: What is Version Control?

Version control records changes to files so you can revert to earlier states if needed. Without version control, accidentally deleting code could cause major problems.

Types of version control:

Version control is essential for tracking changes, collaboration, and managing project history.

Lesson 3: Why Developers Use Git

Git helps developers in multiple ways:

Lesson 4: What is GitHub?

GitHub is an online platform for hosting Git repositories. It allows you to store projects, collaborate with others, and showcase your portfolio. Key features:

Lesson 5: Git vs GitHub

Git is a version control tool installed locally. GitHub is an online platform that hosts Git repositories. Use Git to manage projects on your computer and GitHub to store and share them online.

Lesson 6: Install Git

Steps to install Git:

  1. Go to git-scm.com
  2. Download your system version
  3. Install using default settings
  4. Verify installation with git --version

Lesson 7: Configure Git

After installation, configure your name and email:

git config --global user.name "Your Name"
git config --global user.email "your@email.com"

Check configuration:

git config --list

Lesson 8: Understanding Git Bash

Git Bash is a terminal to run Git commands. You can navigate folders, create files, and execute Git operations efficiently.

ls
cd foldername
mkdir project

Lesson 9: Your First Git Project

Create your first project:

mkdir myproject
cd myproject
git init
touch index.html
git status

You now have a local Git repository ready for version control.

Lesson 10: Git Workflow

The Git workflow:

  1. Modify files
  2. Add to staging (git add)
  3. Commit changes (git commit)
  4. Push to GitHub (git push)

Example:

git add .
git commit -m "Initial commit"
git push

Lesson 11: git init

The git init command initializes a new Git repository in your project folder. This creates a hidden .git folder that stores all the version history and configuration.

Example:

mkdir myproject
cd myproject
git init

After running git init, your folder becomes a Git repository, ready to track changes. Always use this for new projects.

Lesson 12: git status

git status shows the state of your repository. It tells you:

Example:

git status

Always check git status before committing to avoid mistakes.

Lesson 13: git add

The git add command moves changes from the working directory to the staging area. Only staged changes will be committed.

Example:

git add index.html
git add .

Using git add . stages all changes in your folder. Be careful to stage only what you want.

Lesson 14: git commit

git commit saves staged changes to the repository with a descriptive message.

Example:

git commit -m "Added homepage HTML structure"

Best practice: Write meaningful commit messages that describe the changes.

Lesson 15: git log

git log shows the history of commits in your repository.

Example:

git log

Each commit has a unique ID, author, date, and message. This allows you to track all changes made to your project.

Lesson 16: Create GitHub Account

GitHub is an online platform to store and manage your repositories. To create an account:

  1. Go to github.com
  2. Click "Sign Up"
  3. Enter your username, email, and password
  4. Verify your email

Once your account is ready, you can start hosting repositories online.

Lesson 17: Create Repository

After logging into GitHub, you can create a new repository:

  1. Click the "+" icon → "New repository"
  2. Give it a name (e.g., myproject)
  3. Choose Public or Private
  4. Optionally add a README
  5. Click "Create repository"

This is where your project will be stored online.

Lesson 18: git remote add

To connect your local repository to GitHub, you need to add a remote:

git remote add origin https://github.com/username/myproject.git

This tells Git where to push your code online. Use git remote -v to verify the connection.

Lesson 19: git push

The git push command uploads your local commits to the GitHub repository.

git push -u origin main

“-u origin main” sets the upstream branch. After the first push, you can simply use git push.

This is how your project becomes visible on GitHub.

Lesson 20: git pull

git pull downloads the latest changes from GitHub to your local repository.

git pull origin main

This keeps your local project up-to-date, especially when working in a team.

Best practice: Always pull before starting new changes to avoid conflicts.

Lesson 21: git clone

git clone is used to copy a repository from GitHub to your local machine.

git clone https://github.com/username/myproject.git

This is essential when starting to work on an existing project.

Lesson 22: Branching Basics

Branches allow you to work on new features or experiments without affecting the main project.

Example: You can create a feature-login branch to build login functionality without touching the main branch.

Lesson 23: git branch

Create a new branch:

git branch feature-login

List all branches:

git branch

Lesson 24: git checkout

Switch between branches using git checkout:

git checkout feature-login

Now, any changes you make affect only this branch.

Lesson 25: git merge

Merge changes from one branch into another:

git checkout main
git merge feature-login

This integrates your feature branch into the main project.

Lesson 26: Merge Conflicts

Sometimes Git cannot merge automatically. Conflicts happen when two branches change the same line.

Steps to resolve:

  1. Open conflicting file
  2. Look for conflict markers <<<<<<<
  3. Edit the file to fix conflicts
  4. Stage and commit the resolved file

Lesson 27: GitHub Pages

GitHub Pages allows you to host static websites for free.

  1. Push your project to GitHub
  2. Go to repository settings → Pages
  3. Select the branch and folder to publish
  4. Save settings and visit the link

Lesson 28: Custom Domain

You can connect your own domain to GitHub Pages:

  1. Add your domain in repository → Pages settings
  2. Create a CNAME file in your repository
  3. Update DNS records to point to GitHub

Lesson 29: Fix HTTPS

To secure your site with HTTPS:

  1. Go to repository settings → Pages
  2. Enable "Enforce HTTPS"
  3. Wait a few minutes for GitHub to issue a certificate

HTTPS ensures your website is secure and trusted.

Lesson 30: Final Project

Combine everything you’ve learned:

  1. Create a local project and initialize Git
  2. Make multiple commits with meaningful messages
  3. Create a feature branch, implement changes, merge into main
  4. Push project to GitHub
  5. Host it using GitHub Pages
  6. Connect custom domain and enable HTTPS

This final project demonstrates mastery of Git and GitHub workflow, and it can serve as a portfolio project for freelancing.