How Git Works Internally: Objects, Branches & the .git Directory
Git is a content-addressable filesystem — a key-value store where the SHA-1 hash of content becomes its identifier. The entire database lives in the hidden .git directory, storing everything as four object types: blobs (file content), trees (directory structure), commits (snapshots), and tags (named markers).
When you git add, file content is hashed into a blob and tracked in the staging index. When you git commit, the staging area becomes a tree object, which gets wrapped with metadata into a commit object, and the branch ref updates to point to it. A branch is literally a 41-byte text file containing a commit SHA — creating one is just writing a file. Pack files with delta compression keep repositories efficient despite storing full snapshots.
Understanding this model demystifies merge conflicts, detached HEAD states, and makes recovering lost commits trivial instead of terrifying.
Related Blogs
How Docker Really Works: Images, Layers & Containers
- Published on
- Reading time
- 6 min read
Enhance Your macOS Terminal with Oh My Zsh, Autosuggestions, and Powerlevel10k
- Published on
- Reading time
- 6 min read
Why Use NVM? Manage Node.js Versions Like a Pro
- Published on
- Reading time
- 4 min read