Skip to main content

Command Palette

Search for a command to run...

Inside Git

Published
3 min read

Most devs use Git for years… but the single most ignored thing in their repo is .git/.

.git/ is the real repository.
Your actual project files are just the working directory version of whatever snapshot HEAD is pointing to.

Let’s break this down from inside → out.

Architecture = Doubly Linked List

Git internally chains commits like a Doubly Linked List.
Every commit knows:

  • parent(s)

  • its hash

  • its snapshot of the repo at that time

So each commit is like a checkpoint node.

Snapshot Mental Model

  • Git does not track single file deltas like a DB.

  • Git stores whole repo state → snapshot.

  • So the commit itself = a full point-in-time repo picture.

Git uses storage (space) to buy speed of commit operations.

Hash TypeLengthUsage
SHA140 hex charsDefault
SHA256larger secure variantgit init --object-format=sha256

Inside .git/ Folder

ItemMeaning
configremote url, branch, repo configs
HEADpointer (which branch / commit is “current”)
packed-refsoptimized / compressed reference store
refs/heads/*one file per local branch (contains commit hash)
refs/remotes/*commit hashes for origin remote branches
refs/tagscommit hashes of tags
refs/stashreference to stash commit
objects/🔥 the real repo snapshot objects live here
hooks/event trigger scripts
logs/history of pointer movement (reflogs)

The working directory rebuilds itself by reading which object/tree/blob a commit points to.

Objects Folder = Snapshot Store

  • Each file content → stored as blob

  • Directory → stored as tree

  • Commit → pointer + metadata + parent hash + tree hash

  • pack/ → delta compression of old objects to save space


How HEAD Works

  • checkout = just reposition HEAD pointer to another commit/branch

  • branch create = creates a new pointer in refs/heads/...

  • commit = take a new snapshot + write object → move HEAD

Your source files are just the render of the commit tree HEAD points to.


Commands Explained with Linked List Brain

CommandWhat Happens
git initcreate .git/ folder + initial branch pointer
git addstore content to staging/index (inside .git)
git commitcreate snapshot object + move HEAD
git commit --amendre-create last commit (new hash), old objects may still remain
git mergeappend commits + write merge commit (multiple parents)
git rebase mastercopy & replay commits → new hashes → cleaner linear history
git gccompress objects, clean unreachable objects (NOT wiping staging index)

Hooks (the most practically useful ones)

HookWhen
pre-commitbefore commit write (lint, checks)
commit-msgvalidate commit content
post-commitafter commit finalizes
pre-pushblock/allow pushes
pre-rebasebefore a rebase starts
post-checkoutafter switching branches/files
pre-auto-gcbefore auto garbage collection

Hooks = listeners for Git events. Most powerful + underused feature in enterprise teams.


Conclusion

Git is NOT a text diff tool. Git is:

Snapshot Store + Pointer Manipulation Machine If your .git/ folder exists → your repo exists.
Even if project files got deleted accidentally. Deleting .git/ → means repo knowledge is gone.