Index

Git Internals: Three Guides That Build the Storage Model by Hand

Three guides that build Git's storage model by hand: the loose object format, the tree and commit layout, and the packfile format with hand-encoded deltas, in Python and C++. Every hash is checked against real Git, and every pack is read back by real Git.

Written November 11, 2026 · Tested with GCC 13.3.0 · 2 min read

By the end of this guide
  • What this page is
  • Loose objects first (2 guides)
  • Packfiles and deltas (1 guide)
  • Also on the site

What this page is

An index of the three guides on the site that build Git's storage model from scratch instead of calling Git's commands: the loose objects a repository is made of, the trees and commits that link them, and the packfiles that compress them for transfer. Each line states what the guide builds, in the guide's own words, and links to the guide, which carries the full code, the probe output, and the measured numbers.

Loose objects first (2 guides)

  • Build Your Own Mini-Git: Objects, Trees, Commits, Packfiles; About 120 lines of stdlib Python that writes blobs, trees, commits, and an annotated tag, plus a hand-written packfile, into a repository created with git init. Every hash is cross-checked against Git 2.43.0 plumbing on the same fixture, and the failures stay in with the exact errors.
  • Write Git Objects by Hand: A Mini-git in C++; A C++ program that writes a blob, a tree, and a commit into a fresh repository. The blob hash matches git hash-object exactly, the tree hash matches git mktree exactly, and git cat-file, git log, and git fsck all read the result. A one-byte tamper test shows what happens when the bytes stop agreeing.

Packfiles and deltas (1 guide)

  • Writing Git Packfiles in C++: Deltas, Indexes, and the Streaming Win; A C++ program that writes a three-object pack in 221 bytes, hand-encodes a REF_DELTA entry that real Git accepts and reconstructs byte for byte, and streams a 5 MB blob at 2.94 times lower peak memory than the in-memory Python version. Measured on Git 2.43.0 with g++ 13.3.0. This is the extension the Python mini-git guide names: it does the two things that guide leaves out, three objects in one pack and a hand-encoded delta.

Also on the site

Keep Exploring