Git database internals

Git database internals

Most of the time, we use Git like this:

git add .
git commit -m "fix bug"
git push

And honestly, for daily work, this is enough. We do not wake up and say, “hmm, today I want to think about object stores, reachability bitmaps, and changed-path Bloom filters.” Normal people drink coffee.

But Git is not only a command line tool. Under the hood, Git is very close to a small distributed database. It stores data on disk, gives us queries over that data, builds indexes to make those queries faster, compresses old data, and synchronizes different copies of the database between machines.

Git is the distributed database at the core of your engineering system.

This sentence looks dramatic, but after reading the series, it makes sense. Your repository is not just files. It is a database of project history.

Normal database
  table -> row -> index -> query -> replication

Git
  object store -> commit/tree/blob -> commit-graph/bitmap -> git log/blame/fetch -> push/pull

So in this post, I want to go through the 5 GitHub articles and explain them in a human way. Not like “Git has objects and packfiles, good luck.” More like: what problem is Git solving, why the solution exists, and where the clever part is hiding.


Big map before we start

GitHub article Main question Simple answer
Part I: packed object store How does Git store data? As objects, then compressed into packfiles.
Part II: commit history queries How does git log work fast? Git walks a commit graph and uses commit-graph indexes.
Part III: file history queries How does Git know who changed a file? It compares trees and uses Bloom filters to skip useless work.
Part IV: distributed synchronization How does fetch/push send only missing data? It computes reachable set differences using wants/haves, frontiers, and bitmaps.
Part V: scalability What happens when the repo becomes huge? You need repo sharding ideas: multi-repo, submodules, monorepo, partial clone, etc.

The beautiful part is that every section has the same pattern:

Data gets big
Naive way becomes slow
Git adds a smart structure
Queries become fast again

Basically Git is saying: “I am just a version control system” and then quietly doing database engineering in the background.


Part I — Packed object store

Let’s start with the most important folder in Git:

.git/objects

This folder is the object store. It is where Git stores the actual data of your repository.