How Git Works Internally

In this article we will dive into how actually Git works and how it magically remembers all the versions of our code files. Well before moving on we need to know one simple idea that “Git is a memory box of your project”. It remembers each and every version of your code. so you can:
go back in time
track what changed
and work safely without fear
Everything git knows lives in one place.
What is the .git folder
When you run:
git init
Git creates a hidden folder called .git
You can think of .git folder as Git’s brain.
Your files = body
.gitfolder = brainNo brain → no memory → no Git
So if you delete .git folder
❌ No history
❌ No commits
❌ No branches
It just becomes a normal folder again. That is how powerful .git folder is.
What does Git store in its brain?
Git stores snapshots.
📸 A snapshot =
“How all files looked at one moment”
Not instructions.
Not diffs.
Pictures of your project.

Git’s building blocks
Git uses only 3 main blocks:
1️⃣ File content (Blob)
The text inside a file
Git doesn’t care about file names here
2️⃣ Folder list (Tree)
Knows:
file names
which content belongs to which file
3️⃣ Snapshot (Commit)
A commit says:
Which files existed
What was inside them
A message like: “Add login feature”
What REALLY happens during git add
You run:
git add file.js
Git does this:
Reads the file content
Saves it safely in
.gitAdds it to the staging checklist
That’s it.
❗ git add does NOT save history
❗ It only prepares
What REALLY happens during git commit
Now Git takes the photo 📸
When you run:
git commit -m "message"
Git:
Looks at the staging checklist
Takes a snapshot
Stores it forever
Moves the timeline forward
🎉 That snapshot is your commit.
🔐 What are Git hashes? (No math, promise)
Git gives everything a unique ID.
Like:
Aadhaar number
Fingerprint 🖐️
If the content changes:
➡️ the ID changes
This means:
No fake history
No silent changes
100% trust
Git — Simple Summary
Git is a memory system for your code. It remembers every version of your project.
The
.gitfolder is Git’s brain. All history, commits, and branches live there.Git saves snapshots, not just changes.
Your files live in the working directory.
The staging area is a checklist of what will go into the next snapshot.
git add= choose files for the snapshot.git commit= take the snapshot and save it forever.Git uses hashes (unique IDs) to make sure nothing is changed or corrupted.
-- Mental model: edit → select → snapshot → remember forever.




