Git Finally Clicked When I Understood This
You probably use Git every day, like I do.
You run git add, git commit, git push.
Most of the time, it works.
But the moment something goes wrong—merge conflicts, weird states, lost commits—Git suddenly feels… unpredictable.
That’s not because Git is complicated.
It’s because we usually learn Git as a set of commands, not as a system.
The Shift That Makes Git Click
Here’s the idea that changes everything:
Git is just a content-addressable database.
In simple terms, it stores data, gives it a hash, and links things together.
Once you see this, Git stops feeling like magic.
The 3 Building Blocks of Git
Everything in Git is built from just three object types.
1. Blob — File Content
A blob is just the contents of a file.
- No filename
- No metadata
- Just raw data
If two files have the same content, Git stores them only once.
2. Tree — Folder Structure
A tree represents a directory.
It maps:
- filenames → blobs
- directories → other trees
Think of it as a snapshot of your project structure.
3. Commit — A Snapshot with Context
A commit points to a tree and adds:
- author
- message
- parent commit
So a commit is not “changes”—it’s a snapshot of your project at a moment in time.
Let’s Look Under the Hood
Git has a set of low-level commands called plumbing commands.
These are what the high-level commands actually use internally.
You don’t need all of them—just a few will change how you think.
1. git hash-object
This command takes content, hashes it, and stores it.
echo "hello" | git hash-object -w --stdin
It returns a hash like:
b6fc4c620b67d95f953a5c1c1230aaab5db5a1b0
That hash is the identity of the content.
Why this matters:
Git tracks content, not files.
- git cat-file
This lets you inspect anything inside Git.
git cat-file -p <hash>
You can use it to:
read commits
view file contents
inspect trees
Why this matters:
Nothing in Git is hidden—you can inspect everything.
- git write-tree
This takes your staging area and turns it into a tree object.
git write-tree
Why this matters:
The staging area is literally a blueprint for your next commit.
What git commit Actually Does
When you run:
git commit -m "message"
Git is really doing this:
Save staged files as a tree
Create a commit pointing to that tree
Move the branch to the new commit
That’s it.
No magic—just structured data.
Final Thought
Once you understand this, Git stops being unpredictable.
It becomes a system you can reason about.
If you found this useful, I’d love to hear your thoughts or feedback.
Email: sarveshmohite2005@gmail.com
LinkedIn: https://www.linkedin.com/in/sarvesh-mohite-0a6344251/
Twitter/X: https://x.com/SarveshMohite2
Top comments (0)