๐ฎ Git Physiology - Explained Like You're 5!
No fluff. Just the stuff you need for tomorrow. Let's go!
๐ค First - What Even IS Git?
Imagine you're building a LEGO castle. Every time you finish a cool part, you take a photo of it. If you break something later, you can look at your old photo and rebuild it exactly.
Git = the camera that takes photos of your code.
๐๏ธ The 3 Zones (Most Important Thing!)
Think of it like doing laundry:
๐ Your Floor โ ๐งบ Laundry Basket โ ๐๏ธ Wardrobe
(Working Directory) (Staging Area / Index) (Repository)
"I'm editing stuff" "I'm ready to save this" "It's saved forever"
| Zone | Real Name | What happens here |
|---|
| ๐ Floor | Working Directory | You write and edit files here |
| ๐งบ Basket | Staging Area (Index) | You pick what to save with git add |
| ๐๏ธ Wardrobe | Repository | Permanently saved with git commit |
๐งฌ Git's "Physiology" - The 4 Object Types
This is the BIOLOGY of Git - what lives inside .git/objects/ folder.
Think of it like a Library System:
๐ BLOB = The actual pages of a book (raw file content)
๐ TREE = The bookshelf (folder structure, lists blobs & trees)
๐ธ COMMIT = A photo of the whole library at one moment
๐ท๏ธ TAG = A sticky label on a special commit ("Version 1.0!")
Visually:
COMMIT
โ
โโโโ TREE (root folder)
โ
โโโโ BLOB (file: index.html)
โโโโ BLOB (file: style.css)
โโโโ TREE (subfolder: /images)
โ
โโโโ BLOB (file: logo.png)
Every single object gets a SHA-1 hash - a unique 40-character ID like:
a3f5b27c1d9e0f8a2b4c6d7e8f9a0b1c2d3e4f5a
Git names everything by this hash. It's like a fingerprint - no two objects ever get the same one.
๐ธ What's Inside a COMMIT?
A commit is just a tiny text file that says:
tree a3f5b27... โ points to the folder snapshot
parent 9d2c1e4... โ points to the PREVIOUS commit
author John, July 11 โ who made it
message "Fixed the bug" โ what they wrote
Commits form a chain going backwards in time:
[Commit 4] โโโ [Commit 3] โโโ [Commit 2] โโโ [Commit 1]
"Fix login" "Add login" "Add CSS" "First commit"
Each commit points to its parent. That's the whole history!
๐ฟ Branches - The Coolest Part
A branch sounds scary but it's just a sticky note with a commit hash written on it. That's literally it.
main โโโโโโโโโโโโโโโ [C1] โ [C2] โ [C3]
โ
(sticky note: "main")
When you make a new commit, the sticky note just moves forward:
Before: main โ C3
After: main โ C4 (new commit, note moved up)
Branches = Parallel Universes ๐๐
main: C1 โ C2 โ C3
\
feature: โ C4 โ C5 (your new feature, safe from main)
You work on feature without breaking main. When done, you merge them together.
๐ HEAD - "You Are Here"
HEAD is like the ๐ pin on Google Maps. It tells Git "this is where you currently are."
HEAD โ main โ C3
If you switch branches:
HEAD โ feature โ C5
HEAD almost always points to a branch, which points to a commit.
๐ Merge vs Rebase
Merge (keeping both histories)
main: C1 โ C2 โ C3 โโโโโโโโโโโ M โ merge commit
\ /
feature: โ C4 โ C5 โ
Rebase (pretend you started later, cleaner history)
Before:
main: C1 โ C2 โ C3
feature: C1 โ C2 โ C4 โ C5
After rebase:
main: C1 โ C2 โ C3 โ C4' โ C5'
โ
(replayed on top of C3)
๐ The .git Folder - Git's Brain
When you run git init, Git creates a hidden folder called .git. Everything lives here:
.git/
๐ objects/ โ ALL your blobs, trees, commits (the actual data)
๐ refs/ โ branches & tags (just tiny files with SHA hashes!)
๐ HEAD โ one line: which branch you're on right now
๐ index โ the staging area (your laundry basket)
๐ config โ settings for this repo
Fun fact: A branch file is literally just a text file with one line - the SHA hash of the latest commit. That's why making a branch takes 0 seconds!
โก Commands You MUST Know
git init # Create a new repo (makes .git folder)
git status # "What's changed?"
git add . # Move ALL changes to staging (laundry basket)
git add filename # Move ONE file to staging
git commit -m "msg" # Take the snapshot, save to repo
git log # See all past commits (photos)
git log --oneline # Same but shorter
git branch # List all branches
git branch new-name # Create a new branch
git checkout main # Switch to 'main' branch
git switch main # Same thing, newer way
git merge feature # Merge 'feature' into current branch
git rebase main # Replay your commits on top of main
git clone <url> # Download a whole repo
git pull # Download new changes from remote
git push # Upload your commits to remote
๐บ๏ธ Full Story - Start to Finish
1. git init โ ๐ .git folder created. Git is watching!
2. edit files โ ๐ Working Directory has changes
3. git add . โ ๐งบ Changes move to Staging Area
4. git commit โ ๐ธ Snapshot saved as Commit object in .git/objects
5. git branch feat โ ๐ท๏ธ New sticky note "feat" created
6. git switch feat โ ๐ HEAD now points to "feat"
7. edit + add + commit โ ๐ธ New commit, "feat" moves forward
8. git switch main โ ๐ HEAD back to "main"
9. git merge feat โ ๐ Both histories joined together
10. git push โ โ๏ธ Commits uploaded to GitHub/remote
๐ง Exam Cheat Sheet - Memorize This!
| Concept | One-line answer |
|---|
| Blob | Stores raw file content |
| Tree | Stores folder structure (points to blobs + trees) |
| Commit | Snapshot with author, message, parent, and tree pointer |
| Tag | A permanent label on a commit |
| HEAD | Pointer to your current location |
| Branch | A movable pointer to a commit |
| Staging Area | The zone between editing and committing |
| SHA-1 | Unique 40-char ID for every Git object |
| Merge | Combine two branches, creates a merge commit |
| Rebase | Replay commits on a new base, linear history |
| .git/objects | Where ALL data is physically stored |
| .git/refs | Where branch/tag pointers are stored |
Good luck tomorrow! You've got this. ๐ Remember: 3 zones, 4 objects, branches are just sticky notes, HEAD is your GPS pin.