A minimal but real Git implementation in pure Python. It can init a repository, hash and inflate objects, build trees from a working directory, create commits, and clone a real repository over the smart HTTP protocol — pack files, deltas, and all. No libgit2, no git binary, no third-party Git libraries.
Built in under 48 hours with Claude Code while reaching CodeCrafters Python leaderboard rank #13.
If you searched for "how does git work internally", "git objects in Python", "git packfile format", or "implement git from scratch" — this repo is a complete, readable reference.
$ mkdir demo && cd demo
$ /path/to/your_program.sh init
Initialized git directory
$ /path/to/your_program.sh hash-object -w README.md
a1b2c3...
$ /path/to/your_program.sh ls-tree --name-only <tree-sha>
README.md
src
$ /path/to/your_program.sh clone https://github.com/codecrafters-io/git-sample-1 clonedinit— creates.git/withobjects/,refs/, andHEADcat-file -p <sha>— zlib-inflate and print an objecthash-object [-w] <file>— compute SHA-1 and optionally write the blobls-tree [--name-only] <tree>— parse and list tree entrieswrite-tree— recursively hash a working directory into a tree objectcommit-tree <tree> -p <parent> -m <msg>— build a commit objectclone <url> <dir>— real smart-HTTP clone:GET /info/refs?service=git-upload-pack+ pkt-line parsingPOST /git-upload-packwithwant/donenegotiation- pack file parsing (PACK header, entry types 1–7)
- delta resolution (ref-delta + ofs-delta, with varint offsets and delta-instruction decoding)
- tree checkout to the working directory
- Zero dependencies beyond the standard library (
zlib,hashlib,struct,urllib) - One file (
app/main.py, ~380 lines) — each Git concept maps to a function you can read top-down
./your_program.sh <command> [args...]Requires uv and Python 3.14.
⚠️ your_program.shoperates on the.gitin your current directory. Run it inside a scratch folder (e.g./tmp/testing) so you don't touch the real repo.
alias mygit=/path/to/your/repo/your_program.sh
mkdir -p /tmp/testing && cd /tmp/testing
mygit initGit's storage model (content-addressed blobs → trees → commits) becomes obvious once you've written it in ~400 lines. The clone path in particular — pkt-lines, packfile format, delta reconstruction — is the part most tutorials skip, and it's all here.
Part of the CodeCrafters "Build Your Own Git" challenge.