Why Learn Internals?
For many developers, Git is a black box. You type the magical incantations (add, commit, push), and hopefully, it works. When it doesn't, it feels like disaster strikes — you're staring at a detached HEAD or a merge conflict with no idea what actually happened.
By understanding how Git works internally, you stop relying on magic. Complex operations like rebasing, cherry-picking, and resolving conflicts become understandable, predictable actions with clear cause and effect. You can reason about what Git is doing rather than guessing.
At its core, Git is a content-addressable key-value store — a database where every piece of data is stored under a key derived from the data itself. That key is a SHA-1 hash. The entire version control system is built on top of this simple foundation. Understanding this one idea unlocks everything else.
The .git Directory
Every Git repository has a .git directory at its root. This is Git's entire world. Delete it, and your project becomes a plain folder with no history. Everything Git knows — every commit, every branch, every tag — lives inside .git.
.git/
├── HEAD ← Points to the currently checked-out branch
├── config ← Repository-level configuration
├── objects/ ← The key-value database (all commits, files, trees)
└── refs/ ← Human-readable pointers to commits
├── heads/ ← Local branches
├── tags/ ← Tags
└── remotes/ ← Remote-tracking branches
When you run git status, git log, or git diff, Git is reading and interpreting the contents of this directory. There is no server, no daemon, no magic — just files.