Inside Git
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 Type | Length | Usage |
| SHA1 | 40 hex chars | Default |
| SHA256 | larger secure variant | git init --object-format=sha256 |
Inside .git/ Folder
| Item | Meaning |
config | remote url, branch, repo configs |
HEAD | pointer (which branch / commit is “current”) |
packed-refs | optimized / compressed reference store |
refs/heads/* | one file per local branch (contains commit hash) |
refs/remotes/* | commit hashes for origin remote branches |
refs/tags | commit hashes of tags |
refs/stash | reference 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
blobDirectory → stored as
treeCommit → 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
| Command | What Happens |
git init | create .git/ folder + initial branch pointer |
git add | store content to staging/index (inside .git) |
git commit | create snapshot object + move HEAD |
git commit --amend | re-create last commit (new hash), old objects may still remain |
git merge | append commits + write merge commit (multiple parents) |
git rebase master | copy & replay commits → new hashes → cleaner linear history |
git gc | compress objects, clean unreachable objects (NOT wiping staging index) |
Hooks (the most practically useful ones)
| Hook | When |
| pre-commit | before commit write (lint, checks) |
| commit-msg | validate commit content |
| post-commit | after commit finalizes |
| pre-push | block/allow pushes |
| pre-rebase | before a rebase starts |
| post-checkout | after switching branches/files |
| pre-auto-gc | before 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.
