Learn Git Step by Step

Master Git from the fundamentals to advanced workflows through structured lessons, practical examples, and real-world commands.

Home

Learning Roadmap

Follow the topics in order to build a solid understanding of Git.

Introduction to Git

Before learning Git commands, it's important to understand what Git is and why developers use it.

📖 What is Git?

Git is a distributed version control system that helps developers track changes in their source code. It allows multiple developers to work together efficiently while maintaining a complete history of every change made to a project.

🎯 Why Use Git?

  • Track every change made to your project.
  • Work safely without losing previous versions.
  • Collaborate with other developers.
  • Manage multiple features using branches.
  • Integrate easily with GitHub.

⚡ Key Features

Version History

Restore previous versions anytime.

Branching

Develop new features independently.

Collaboration

Multiple developers can work together.

Backup

Your complete project history is preserved.

Installing Git & Basic Commands

Before using Git, you need to install it and configure your identity.

💻 Install Git

Download Git from the official website and install it on your operating system.

Download Git

⚙ Configure Git

Set your username and email. These details will appear in every commit.

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

📂 Create Your First Repository

Create a new project folder and initialize Git.

mkdir MyProject
cd MyProject
git init

📌 Check Repository Status

View the current state of your project.

git status

➕ Stage Files

Add files to the staging area.

git add index.html
git add .
git add style.css

💾 Commit Changes

Save your work permanently.

git commit -m "Initial Commit"

Repository Management

Learn how to inspect your repository, restore changes, remove files, and manage your project history.

📜 View Commit History

Display all commits made in your repository.

git log

Useful for checking previous commits, commit IDs, authors, and dates.

🔍 View Changes

Compare modified files with the last commit.

git diff

♻ Restore a File

Discard local changes made to a file.

git restore index.html

🗑 Remove Files

Delete a file and stage the deletion.

git rm file.txt

📦 Rename Files

Rename a tracked file.

git mv oldname.txt newname.txt

⏪ Reset Staging Area

Unstage a file without deleting your work.

git reset index.html

Branching & Merging

Branches allow developers to build new features safely without affecting the main project.

🌿 Create a Branch

git branch feature-login

Creates a new branch named feature-login.

🔀 Switch Branch

git checkout feature-login

Move from the current branch to another branch.

⚡ Create & Switch Together

git checkout -b feature-navbar

Creates a new branch and switches to it immediately.

📋 List All Branches

git branch

🔗 Merge Branch

git checkout main

git merge feature-login

Merge completed work into the main branch.

❌ Delete Branch

git branch -d feature-login

📌 Best Practices

  • Create a new branch for every feature.
  • Keep branch names meaningful.
  • Merge only after testing.
  • Delete branches after merging.

Working with GitHub

Learn how to connect your local Git repository with GitHub and collaborate online.

📥 Clone a Repository

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

Downloads an existing GitHub repository to your computer.

🔗 Connect Local Repository

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

Links your local project to a remote GitHub repository.

⬆ Push Changes

git push -u origin main

Upload your commits to GitHub.

⬇ Pull Latest Changes

git pull origin main

Download and merge the latest changes from GitHub.

🔄 Fetch Changes

git fetch origin

Downloads new commits without merging them.

🌍 View Remote Repository

git remote -v

Displays all configured remote repositories.

Advanced Git

Master powerful Git features used in professional software development.

📦 Save Work Temporarily

git stash

Stores your uncommitted changes temporarily.

📤 Restore Stashed Work

git stash pop

Restores the latest stashed changes.

🔀 Rebase Branch

git rebase main

Replays your branch commits on top of another branch for a cleaner history.

🍒 Cherry Pick

git cherry-pick commit_id

Apply a specific commit from another branch.

🏷 Create a Tag

git tag v1.0

Mark an important release or version.

↩ Revert a Commit

git revert commit_id

Undo a commit without rewriting project history.

💡 Tips

  • Commit small, meaningful changes.
  • Write clear commit messages.
  • Pull before pushing.
  • Use branches for new features.
  • Never force push to shared branches unless necessary.
  • Keep your repository clean and organized.