Skip to main content

Command Palette

Search for a command to run...

How Git Works Internally: The Library in Your Laptop

Updated
2 min read

Imagine Rohan, a young developer, staring at his .git folder wondering, "Where does Git hide all my code's past lives?" The answer is simpler than you think. Git is basically a magical librarian living inside your project.

The .git Folder: Git's Library Building

When Rohan types git init, Git doesn't just say "hello", it builds an entire library. This hidden .git folder contains:

  • objects/: The underground vault where every version sleeps

  • refs/: Post-it notes marking where each branch is

  • HEAD: A bookmark showing where Rohan is reading now

  • config: The library's rulebook

Git Objects: Three Friends Who Remember Everything

Meet Git's three best friends who never forget:

Blob is the Photocopier: When Rohan runs git add index.html, Blob immediately makes a perfect photocopy of the file's content, gives it a unique fingerprint based on what's inside, and files it away. If two files are identical, they share the same fingerprint.

Tree is the Librarian's Map: Tree knows the layout. It says, "In the src folder, we have app.js (fingerprint: a1b2c3) and style.css (fingerprint: d4e5f6)." It connects folders to files using these fingerprints.

Commit is the Family Photo: When Rohan types git commit -m "Fixed login bug", Commit snaps a group photo. It has Rohan's message, his email, a link to the main Tree's map, and a link to the previous family photo (the parent commit).

# git add style.css
1. Git reads style.css's content
2. Creates a fingerprint (like a1b2c3...)
3. Stores a perfect copy in .git/objects/a1/b2c3...

# git commit -m "Make button blue"
1. Creates a Tree map of the entire project
2. Creates a Commit photo linking to that Tree
3. Connects this photo to the previous one (forming a chain)
4. Moves HEAD bookmark to the newest photo

The 'Aha!' Moment

Here's what changes everything: Git doesn't store changes or differences. It stores complete snapshots of your entire project each time. When Rohan switches branches, Git doesn't "undo" changes, it simply picks up a different family photo and rearranges his laptop to match that moment perfectly.

Understanding this turns Git from scary commands into a logical story. You're not memorizing magic spells, you're just learning how the world's smartest librarian organizes your code's life story.

14 views
How Git Works Internally: The Library in Your Laptop