Welcome back, developer! 👋
Now that you know what Git is and why it matters, it’s time to actually use it like a pro.
This chapter is all about the core Git commands every developer lives on:
init, add, commit, status, log, and diff.
By the end, you’ll not just know Git — you’ll feel it in your fingers. 🧠⚡
Before you can Git things done — you need Git installed! 😎
Open Git Bash and run:
git --version
✅ If you see something like git version 2.xx.x, you’re all set!
brew install git
Or, simply install Xcode Command Line Tools:
xcode-select --install
sudo apt update
sudo apt install git -y
git --version
💡 Pro Tip: Configure your identity once:
git config --global user.name "Your Name"
git config --global user.email "you@example.com"
This makes every commit traceable — your personal developer fingerprint. 🔍
git init — Create a New RepositoryImagine you’ve just started your next million-dollar project 💼 —
to make Git start tracking it, run this inside your project folder:
git init
What happens:
Git creates a hidden folder .git/
It starts tracking all changes in that folder
Your project just became a version-controlled repository
✅ You’ll see:
Initialized empty Git repository in /path/to/project/.git/
💡 Mental Model:
Think of git init as pressing “Start Recording” 🎥 on your project’s timeline.
git add — Stage Your ChangesGit doesn’t auto-track every change you make.
You decide which changes are worth saving using git add.
git add <file-name>
or to add everything:
git add .
💡 Staging Area = The “Ready to Commit” Box
Example:
echo "console.log('Hello World');" > app.js
git add app.js
✅ Git has now “noticed” that file and marked it for the next snapshot.
🧠 Pro Tip:
Always double-check what you’re adding with:
git status
git commit — Save Your Code SnapshotOnce changes are staged, commit them to permanently save in Git’s history:
git commit -m "Added app.js with Hello World script"
💡 Think of a commit as a checkpoint in your project timeline. If your code breaks later, you can always jump back to this commit.
Good messages = good project health.
Bad messages = chaos in production 😬
✅ Good:
git commit -m "Add user login validation"
❌ Bad:
git commit -m "changes"
🪄 Rule of thumb:
Every commit should tell a mini-story of progress.
git status — Check What’s Going OnBefore you commit, always run:
git status
This shows:
Which files are tracked
Which ones are modified
Which ones are staged
Which ones are untracked
Example output:
On branch main
Changes to be committed:
new file: app.js
Changes not staged for commit:
modified: index.html
💡 Why it matters:
Think of git status like your daily project dashboard. Don’t fly blind. 🧭
git log — View Commit HistoryWant to see how your project evolved?
Run:
git log
You’ll see something like:
commit a1b2c3d4e5f6g7
Author: Mahesh Shukla <you@example.com>
Date: Fri Oct 25 18:00:00 2025 +0530
Added app.js with Hello World script
💡 Too long? Simplify it:
git log --oneline
Output:
a1b2c3d Initial commit
c4d5e6f Added Hello World script
🎯 Use this to quickly navigate your version history and identify stable states.
git diff — See What’s ChangedBefore committing, always check what exactly changed:
git diff
This shows the line-by-line difference between your last commit and your current edits.
Example:
+ console.log("Hello Git!");
- console.log("Hello World!");
🧠 Pro Tip:
Run this before git add to avoid committing accidental changes.
It’s your built-in error radar 🛫
Let’s tie everything together 👇
# Step 1: Initialize repo
git init
# Step 2: Create a file
echo "Hello Git!" > hello.txt
# Step 3: Stage it
git add hello.txt
# Step 4: Commit it
git commit -m "Initial commit with hello.txt"
# Step 5: Modify file
echo "Learning Git feels awesome!" >> hello.txt
# Step 6: Check changes
git diff
# Step 7: Stage + commit again
git add hello.txt
git commit -m "Updated hello.txt with learning message"
# Step 8: Review your history
git log --oneline
🧠 You’ve just performed a complete Git workflow from scratch —
the same foundation used by Google, Netflix, and every major tech company. 🚀
| Command | Purpose | Analogy |
|---|---|---|
git init |
Start a new repo | Press “Record” |
git add |
Stage changes | Put items in cart |
git commit |
Save snapshot | Checkout and store receipt |
git status |
Check repo state | Look at your to-do list |
git log |
View commit history | Read your timeline |
git diff |
Compare changes | Spot what’s new or broken |
Every commit = a checkpoint in your project’s time machine
add before commit = pack before you save
status + diff = your debugging radar
log = your memory lane
The more you visualize these metaphors, the faster Git feels natural. 💪
In the next chapter, you’ll learn:
How to use
git branch,checkout, andmerge
to experiment fearlessly — just like parallel universes in your code.
🧭 Continue your journey → 03-Git-Branching
✍️ Written with ❤️ by Mahesh Shukla — keep committing, keep growing!