Goal
Build a small Git-compatible tool that reads and writes the real .git object store.
Implementing hashing, object serialization, trees, commits, and refs by hand makes the
data model concrete: you see that a commit is a snapshot, a branch is a 41-byte pointer,
and nothing is magic — every porcelain command is manipulation of objects and refs.
Subject: full brief & instructions
Practices
- Git internals — the object types, refs, the index, and the reflog that this exercise reconstructs from scratch.
- Cryptography for engineers — content-addressing is SHA-1/SHA-256 hashing used for identity and tamper-evidence, not secrecy.
Milestones
- The object store. Implement
hash-objectandcat-file: read a file, prepend theblob <size>\0header, zlib-compress, SHA it, and store under.git/objects/ab/cdef…. Round-trip a blob you wrote against realgit cat-file. - Reading trees & commits. Parse tree objects (mode, name, hash entries) and commit
objects (tree, parents, author, message); implement
ls-treeandlogwalking parent pointers. - Writing trees & commits. Implement
write-treefrom a directory andcommit-treeto snapshot it with a parent and message — build a commit real Git can thencheckout. - Refs & HEAD. Read and write refs under
.git/refs/, resolveHEAD(symbolic and detached), and implementcheckoutof a commit into the working tree. - Interop proof. Create commits with your tool, then inspect and continue history with
stock
git— and vice versa — confirming byte-compatible objects.
Stretch goals
- Implement the index and a real
add/status(worktree↔index↔HEAD diffs). - Read packfiles, or implement a basic three-way
merge.
Related
- Write Yourself a Git — subject — the full build spec, object-format details, and acceptance checks for this exercise.
- Git internals — cites this exercise in its
# Practicesection. - Build your own shell — the sibling "reimplement a daily tool" systems exercise.