How Git Works Internally: Blobs, Trees, Commits, and the Object DAG (ELIF8 Guide)
A deep computer science breakdown of Git's internal plumbing: content-addressable storage, SHA-1 object hashing, tree objects, packfile delta compression, and branch pointers.

Header Ad Advertisement
Every day, millions of software engineers run git add ., git commit -m "update", and git push hundreds of times.
Yet, when asked what actually occurs inside the hidden .git folder when a commit is created, many developers imagine that Git simply stores a sequence of text file diffs or line-by-line deltas.
In reality, Git is an elegant, lightning-fast Content-Addressable Cryptographic Object Database.
Here is an in-depth, step-by-step masterclass on the internal plumbing of Git.
1. The Anatomy of the .git Directory
When you run git init in a fresh terminal directory, Git creates a hidden .git folder containing five essential subsystems:
.git/
โโโ HEAD โโโบ Text file containing pointer to current branch (e.g. ref: refs/heads/main)
โโโ config โโโบ Repository-specific settings, remote URLs, and user email
โโโ description โโโบ Used by GitWeb (mostly legacy)
โโโ hooks/ โโโบ Client-side scripts executed before/after commits, merges, and pushes
โโโ index โโโบ The binary Staging Area (tracks file paths, timestamps, and SHA hashes)
โโโ objects/ โโโบ The Content-Addressable Object Database (Blobs, Trees, Commits, Tags)
โโโ refs/ โโโบ Pointers to branches (refs/heads/) and tags (refs/tags/)
2. The Four Fundamental Git Object Types
Inside .git/objects/, Git stores everything as one of four immutable objects, compressed with Zlib and keyed by its SHA-1 (or SHA-256) 40-character hexadecimal hash:
[ COMMIT OBJECT ]
(SHA: 4a2b9f...)
โโโ Tree: d81b4f... (Points to Root Directory Tree)
โโโ Parent: c19a2e... (Previous Commit Hash)
โโโ Author: Sumit <sumit@vyuhantrix.com>
โโโ Message: "Initial production release"
โ
โผ
[ ROOT TREE ]
(SHA: d81b4f...)
โโโ 100644 blob e69de2... (package.json)
โโโ 100644 blob 3b18e5... (README.md)
โโโ 040000 tree a7f29c... (src/ subdirectory)
โ
โผ
[ SRC SUB-TREE ]
โโโ 100644 blob f91b02... (index.ts)
โโโ 100644 blob 884a11... (utils.ts)
1. The Blob (Binary Large Object)
A Blob stores purely raw file data. It does NOT store the filename, the creation date, or the file permissions! If two different files in different folders have the exact same content, Git stores only one single blob object on disk.
2. The Tree Object (Directories & Filenames)
A Tree corresponds directly to a directory folder. It contains a list of entries, where each entry specifies:
- File mode permissions (
100644for standard file,100755for executable,040000for directory). - Object type (
blobortree). - Object SHA hash.
- The human-readable filename (e.g.,
README.mdorsrc).
3. The Commit Object (The Historical Snapshot)
A Commit is a small text metadata envelope that glues everything together:
- A pointer to the top-level Root Tree.
- A pointer to one or more Parent Commit Hashes (enabling branching and merge histories).
- Author and Committer names, email addresses, and UNIX timestamps.
- The commit message.
4. The Annotated Tag Object
An Annotated Tag is an immutable cryptographic marker pointing to a specific commit, containing its own tagger name, date, message, and optional GPG signature.
3. Hands-On Experiment: Peeking Under the Hood with Plumbing Commands
You can inspect Git's raw cryptographic database using Git's low-level "plumbing" commands:
# 1. Create a raw blob and calculate its SHA-1 hash without touching the staging area
$ echo "Hello Learntrix" | git hash-object -w --stdin
b5f12a32c253de97a9f939e6cf6e153b6f272a2e
# 2. Inspect the type of that object in .git/objects/
$ git cat-file -t b5f12a32c253de97a9f939e6cf6e153b6f272a2e
blob
# 3. Read the decompressed content of that blob object
$ git cat-file -p b5f12a32c253de97a9f939e6cf6e153b6f272a2e
Hello Learntrix
4. What is a Git Branch, Really?
In other legacy version control tools (like SVN or CVS), creating a new branch cloned the entire multi-gigabyte codebase into a new directory, taking minutes and wasting disk space.
In Git, a branch is literally a 41-byte plaintext file:
$ cat .git/refs/heads/main
4a2b9f87d3e9185a9bc01824ef78201948ba1204
When you type git branch feature-auth, Git merely writes a 41-byte text file named feature-auth containing the current commit hash!
Creating a branch in Git is instantaneous and costs 0 milliseconds of compute and 41 bytes of disk space.
5. Packfiles & Delta Compression
If Git stores full snapshot blobs rather than diffs, why doesn't a 5-year-old Git repository with 50,000 commits consume hundreds of gigabytes?
The secret is the Packfile Subsystem (git gc / Git Garbage Collection):
- As you make commits, loose object files accumulate in
.git/objects/. - Periodically or during
git push, Git scans objects with similar names and sizes. - Git compresses them into a single binary
.packfile, calculating reverse byte-level deltas (storing the newest version in full, and older historical revisions as tiny binary delta patches). - A companion
.idxindex file allows binary search lookups with microsecond retrieval speeds.
Computer Science Takeaway
Git is an immutable Directed Acyclic Graph (DAG) where commit history is preserved through cryptographic hashing. Understanding blobs and trees transforms Git from a source of merge-conflict anxiety into an intuitive developer superpower.
Mid Content Ad Advertisement
Interactive Developer Tools & Converters
View All Tools โMarkdown Live Editor
Live Markdown editor with split-screen preview and HTML export.
Markdown Previewer
Real-time Markdown to HTML previewer and syntax validator with instant copy.
JSON Formatter
Format, validate and beautify JSON with syntax highlighting and error detection.
Base64 Encoder
Encode and decode Base64 strings and files instantly in your browser.
Editorial Disclaimer
The information in this article is provided for educational and informational purposes only. While we strive for accuracy, content may become outdated as technologies, regulations, and best practices evolve. Learntrix and Vyuhantrix make no warranties regarding the completeness, accuracy, or applicability of the information to your specific situation. Always verify critical information from primary and authoritative sources before implementation.
Last content review: September 2026 ยท Learntrix by Vyuhantrix
Copyright 2026 Vyuhantrix Technologies. All content on Learntrix is the intellectual property of Vyuhantrix. Reproduction, distribution, or republishing of this article โ in whole or in part โ without written permission from Vyuhantrix is strictly prohibited.
Footer Article Ad Advertisement
Related Articles
View all in Programming & Development โ
DSA Roadmap for Beginners in India โ From Zero to Interview-Ready in 6 Months
A complete, honest Data Structures & Algorithms roadmap for Indian students and freshers. Which topics to learn first, which platforms to use, how many problems to solve, and how to crack coding rounds at TCS, Wipro, Google, and startups.

How Your Aadhaar Card Actually Works โ Biometrics, UIDAI & Privacy Explained
How does Aadhaar work technically? What happens when you scan your fingerprint? Where is your data stored? This guide explains UIDAI, biometrics, e-KYC, TOTP and your real privacy rights.
