Most developers use Git every day, but very few understand what Git is actually doing behind the scenes. This blog is not about memorizing commands β itβs about understanding Git.
If you can picture how Git works internally, everything else (commands, errors, conflicts) becomes much easier.
How Git Works (Big Picture)
At its core, Git is a smart storage system.
Instead of thinking:
βGit tracks my filesβ
Think this way:
Git stores snapshots of your project and connects them together.
Each snapshot is saved permanently and identified using a unique hash. All this data lives inside one folder:
π the .git folder
What Is the .git Folder and Why Does It Exist?
The .git folder is the brain of Git.
- It is created when you run
git init - It stores your entire project history
- It remembers every commit, branch, and change
If you delete the .git folder:
Your project becomes a normal folder β Git forgets everything.
So even though you work with visible files, Git only cares about whatβs inside .git.
Structure of the .git Directory (Simple View)
.git/
βββ objects/ β All saved data (snapshots)
βββ refs/ β Branch pointers
βββ HEAD β Where you are right now
βββ index β Staging area
βββ config β Repo settings
βββ logs/ β Movement history
You donβt need to memorize this. Just remember:
- objects store data
- index is staging
- HEAD tells Git your current position
Git Objects: The Core Building Blocks
Git stores everything as objects. There are only three you really need to understand.
1. Blob β File Content
A blob stores the actual content of a file.
Important details:
- No file name
- No folder info
- Same content = same blob
Think of a blob as:
βPure file data, nothing else.β
2. Tree β Folder Structure
A tree represents a directory.
It stores:
- File names
- Folder names
- Links to blobs and other trees
Think of a tree as:
βHow everything is arranged.β
3. Commit β Project Snapshot
A commit is a snapshot of your project at a moment in time.
A commit stores:
- A reference to a tree
- Parent commit(s)
- Message and author info
Think of a commit as:
βThis exact version of the project.β
How Commits, Trees, and Blobs Are Connected
Commit
β
Tree
β
Blobs
Example:
Commit
βββ Tree
βββ index.html β Blob
βββ app.js β Blob
This design is why Git is fast and efficient.
How Git Tracks Changes (Key Idea)
Git does not store line-by-line differences like older systems.
Instead:
Git stores full snapshots, but reuses unchanged parts.
If a file doesnβt change:
- Git reuses the same blob
- No extra space is wasted
Thatβs how Git stays fast even with thousands of commits.
What Happens Internally During git add
When you run:
git add file.txt
Git does this internally:
- Reads the file content
- Converts it into a blob
- Stores the blob in
.git/objects - Updates the index (staging area)
Flow:
Working Directory
β git add
Staging Area (index)
β
Blob stored in .git/objects
At this point:
- The file is staged
- No commit exists yet
What Happens Internally During git commit
When you run:
git commit -m "message"
Git performs these steps:
- Creates a tree from staged files
- Creates a commit object
- Links it to the previous commit
- Moves HEAD forward
Flow:
Staging Area
β git commit
Tree created
β
Commit created
β
HEAD updated
How Git Uses Hashes (Why Git Is Trustworthy)
Every Git object is named using a hash.
This gives Git superpowers:
- Same content β same hash
- Small change β completely new hash
- Corruption is easy to detect
In simple words:
Git knows if anything has been altered or damaged.
This is why Git history is reliable.
The Mental Model to Remember
Donβt memorize commands. Remember this instead:
- Git stores objects
- Objects are connected by references
- Commits are snapshots, not diffs
- HEAD tells Git where you are
Once this clicks, Git feels logical instead of confusing.
Final Thoughts
Understanding Git internally makes you a stronger developer.
Youβll:
- Debug issues faster
- Handle merges confidently
- Explain Git clearly in interviews
Most importantly, Git will finally make sense.
Happy learning π
Top comments (0)