👋 No experience needed — start here if Git confuses you
🌱 Beginner Friendly

Learn Git
the Easy Way

Git is a superpower for developers. This guide teaches it step-by-step, with plain English, real examples, and zero assumed knowledge.

🤔
What is Git?
🛠️
Setup
📸
First Commit
🌿
Branches
☁️
GitHub
🆘
Oops! Help
1
🤔 What Even Is Git?
Understanding the why before the how
⏱ 5 min

Imagine you're writing a big essay. You keep saving it as essay_v1.docx, then essay_v2.docx, then essay_FINAL.docx, then essay_FINAL_REAL.docx...


Git solves this mess. It's a tool that tracks every change you make to your code — automatically, safely, and without creating a million files.

📷
Think of it this way

Git is like a time machine + camera for your code. Every time you say "save this moment", Git takes a snapshot. You can always go back to any past snapshot — even if you accidentally delete everything.

🗂️
Tracks Changes
Every line you add, remove, or edit gets recorded. You can see exactly what changed and when.
Go Back in Time
Broke something? Undo it instantly. Go back to any version of your project from any point in history.
👥
Work in Teams
Multiple people can work on the same project without overwriting each other's work.
🌿
Try Things Safely
Test a new idea in a "branch" — if it fails, delete it. Your main code is always safe.
ℹ️
Git vs GitHub — not the same thing!

Git is the tool on your computer. GitHub is a website that stores your Git projects online (like Google Drive for code). You need Git to use GitHub.


2
🛠️ Setting Up Git
Do this once, forever
⏱ 5 min

Before using Git, you tell it who you are. This info gets attached to every change you make — like a signature.

1
Tell Git your name
Open your terminal (or Git Bash on Windows) and type:
Terminal
$ git config --global user.name "Your Name"
2
Tell Git your email
Use the same email you'll use on GitHub:
Terminal
$ git config --global user.email "you@email.com"
3
Verify it worked
Check your settings are saved correctly:
Terminal
$ git config --list
user.name=Your Name
user.email=you@email.com
You only do this once!

The --global flag means these settings apply to every Git project on your computer.


3
📸 Your First Commit
Taking your first snapshot
⏱ 10 min

A commit is like taking a photo of your code at a specific moment. Let's understand how files move through Git before you start committing.

How Files Move Through Git
📁
Working Directory
Files on your computer
git add
📋
Staging Area
Files ready to save
git commit
🗄️
Repository
Permanent snapshot
git push
☁️
GitHub
Online backup
📬
The staging analogy

Think of staging as packing a box before shipping it. You choose which items go in the box (git add), then seal and send it (git commit). You don't have to pack everything — just what's ready.

1
Start a new Git project
Navigate to your project folder and initialize Git:
Terminal
$ cd my-project # go into your folder
$ git init
Initialized empty Git repository in .../my-project/.git/
2
Check what's going on
git status is your best friend — run it constantly to see what's happening:
Terminal
$ git status
Untracked files:
index.html
style.css
📖
What does "Untracked" mean?

Git can see these files exist, but it's not watching them yet. You haven't told Git to care about them.

3
Stage your files
Tell Git which files to include in your snapshot:
Terminal
$ git add index.html # add one file
$ git add . # add ALL files
4
Take the snapshot (commit!)
Save the staged files with a descriptive message. Write messages like you're explaining it to a teammate:
Terminal
$ git commit -m "Add homepage with navigation"
[main (root-commit) a3f8c1d] Add homepage with navigation
2 files changed, 45 insertions(+)
✍️
Good commit messages matter!

❌ Bad: "fix stuff"    ✅ Good: "Fix login button not working on mobile"

5
See your history
View all the snapshots you've taken so far:
Terminal
$ git log --oneline
a3f8c1d Add homepage with navigation
b2e9d3f Initial project setup
🧠 Quick Check
You edited 3 files. You only want to commit 2 of them. What do you do?
ARun git commit -m "message" immediately
BUse git add on only the 2 files, then commit
CDelete the 3rd file first, then commit all

4
🌿 Branches — Try Things Safely
Experiment without fear
⏱ 10 min

A branch is like a parallel universe for your code. You can experiment, add features, or fix bugs — completely separately from your main code. If it works, merge it in. If it doesn't, just delete the branch.

🎭
Real life analogy

Imagine you're writing a book. You want to try a different ending. You photocopy the book, write the new ending in the copy, and if you like it, replace the original ending. The original is always safe. That copy is a branch.

main ────────────────── ← you're here (main) feat ──── ← working on new feature
1
Create and switch to a new branch
Name it something descriptive — what is this branch for?
Terminal
# Old way (still works)
$ git checkout -b add-dark-mode

# Modern way (preferred)
$ git switch -c add-dark-mode
Switched to a new branch 'add-dark-mode'
2
Check which branch you're on
The * shows your current branch:
Terminal
$ git branch
* add-dark-mode
main
3
Make changes and commit on your branch
Work normally — commits here don't affect main at all:
Terminal
# ... make your changes to files ...
$ git add .
$ git commit -m "Add dark mode toggle to header"
4
Merge your branch back into main
Happy with your changes? Bring them into the main branch:
Terminal
$ git switch main # go back to main
$ git merge add-dark-mode # bring in your feature
Updating a3f8c1d..d8e2b4c
Fast-forward — 1 file changed
5
Clean up — delete the branch
Once merged, you can delete the branch. It's already merged into main, nothing is lost:
Terminal
$ git branch -d add-dark-mode
Deleted branch add-dark-mode

5
☁️ Working with GitHub
Backing up and sharing your code online
⏱ 8 min

GitHub is where your Git project lives online. It's your backup, your portfolio, and how you collaborate with others. The most important commands here are push (upload) and pull (download).

Your Computer ↔ GitHub
💻
Your Computer
Local repository
git push
git pull
🐙
GitHub
Remote repository
1
Connect your project to GitHub
After creating a repo on GitHub.com, link it to your local project:
Terminal
$ git remote add origin https://github.com/yourname/project.git
# "origin" is just the nickname for your GitHub repo
2
Upload (push) your code to GitHub
Send your commits to GitHub for the first time:
Terminal
$ git push -u origin main
Branch 'main' set up to track 'origin/main'
# After this, just use: git push
3
Download (pull) updates from GitHub
If you work on multiple computers, or a teammate pushed changes:
Terminal
$ git pull
Already up to date.
# Or it downloads new changes automatically
4
Clone someone else's project
Download any GitHub project to your computer with its full history:
Terminal
$ git clone https://github.com/torvalds/linux.git
Cloning into 'linux'...
🔁
The daily rhythm

At the start of your day: git pull. After finishing work: git add .git commit -m "..."git push. That's 90% of what you'll do every day.


6
🆘 Oops! Common Fixes
Don't panic — Git can undo almost anything
⏱ 8 min

Everyone makes mistakes. The good news? Git makes most mistakes fixable. Here are the situations beginners hit most often:

🛟
Git's golden safety rule

As long as you've committed it, Git has it. Even if you delete files, run git reflog and you can almost always get everything back.

🙈
I made a typo in my commit message
Fix the last commit message (only before pushing!):
Terminal
$ git commit --amend -m "Corrected commit message"
😬
I staged a file I didn't mean to
Unstage it (your changes are NOT deleted, just removed from staging):
Terminal
$ git restore --staged filename.txt
# file is still edited, just no longer staged
😱
I messed up a file and want the old version back
Throw away unsaved changes in a file and restore it to last commit:
Terminal
$ git restore filename.txt
# ⚠️ This permanently discards your unsaved changes!
⚠️
Warning!

This is one of the few Git commands that can't be undone. Only use it if you're sure you want to discard those changes.

😅
I want to undo my last commit (keep the changes)
This "un-commits" but keeps all your edits in your files:
Terminal
$ git reset --soft HEAD~1
# Your files are untouched, commit is removed
🔍
I lost something — find it with reflog
Git's secret diary of everything that ever happened:
Terminal
$ git reflog
a3f8c1d HEAD@{0}: commit: Add dark mode
b2e9d3f HEAD@{1}: reset: moving to HEAD~1
# Find the SHA you need, then:
$ git switch -c recovery b2e9d3f
🧠 Quick Check
You committed to main by mistake instead of your feature branch. What's the safest fix?
ADelete the entire repository and start over
BUse git reset --hard immediately
CUse git reset --soft HEAD~1 to undo, then switch to the right branch and recommit

📋
Beginner Cheat Sheet
The only commands you need to get started
🏁
Getting Started
git init
Start a new Git project
git clone <url>
Download a project from GitHub
git status
See what's changed (run this constantly!)
📸
Saving Changes
git add .
Stage all changed files
git commit -m "msg"
Save a snapshot with a message
git log --oneline
See your commit history
🌿
Branches
git switch -c name
Create + go to new branch
git switch main
Go back to main branch
git merge name
Merge branch into current
☁️
GitHub Sync
git push
Upload commits to GitHub
git pull
Download latest from GitHub
git push -u origin main
First push to GitHub
🆘
Oops! Fixes
git restore --staged f
Unstage a file
git reset --soft HEAD~1
Undo last commit, keep changes
git reflog
See everything that happened (recovery tool)
Daily Habit
git pull
🌅 First thing every morning
git add . && git commit
💾 After finishing any feature
git push
🌙 Before you finish for the day