A from-scratch implementation of Git in Python. Supports the full object model, branching, merging, diffing, and SSH push/fetch to real GitHub repos -- all without depending on the git binary.
pip install -e .This makes the pit command available globally.
pit init
echo "hello" > readme.txt
pit add readme.txt
pit commit -m "first commit"pit reads your identity from ~/.gitconfig (same file as git). If you already
have git configured, it just works:
git config --global user.name "Your Name"
git config --global user.email "your@email.com"Priority chain (same as git):
GIT_AUTHOR_NAME/GIT_AUTHOR_EMAILenv varsGIT_COMMITTER_NAME/GIT_COMMITTER_EMAILenv vars~/.gitconfig[user] name/email- Error with instructions to configure it
| Command | What it does |
|---|---|
pit init |
Create a new .pit repository |
pit hash-object <file> |
Compute object SHA and store it |
pit cat-file <sha> |
Print the content of an object |
pit add <path> |
Stage a file or directory |
pit write-tree |
Write the index as a tree object |
pit read-tree <sha> |
Load a tree into the index |
pit commit -m "msg" |
Create a commit |
pit log |
Show commit history |
pit show [sha] |
Show commit + diff |
pit status |
Show working tree / index / HEAD state |
pit diff [--cached] [commit] |
Show differences |
pit branch |
List branches |
pit branch <name> [start] |
Create a branch |
pit checkout <branch-or-sha> |
Switch HEAD |
pit tag <name> [sha] |
Tag a commit |
pit merge <commit> |
Merge a commit into HEAD |
pit merge-base <c1> <c2> |
Find merge base |
pit reset <commit> |
Move HEAD to a commit |
pit k |
Visualize commit graph (requires Graphviz) |
| Command | What it does |
|---|---|
pit remote add <name> <url> |
Store a named remote |
pit remote list |
List stored remotes |
pit push <remote> <branch> |
Push objects and update remote ref |
pit fetch <remote> |
Fetch objects and remote-tracking refs |
Remote URLs support both forms:
pit remote add origin git@github.com:user/repo.git
pit push origin masterOr use a URL directly:
pit push git@github.com:user/repo.git masterEverything is written from scratch -- no calls to the git binary. The components are:
data.py-- Object storage (blob, tree, commit) with git-compatible hashing (type size\0content)base.py-- Core operations (add, commit, merge, diff tree walking, branch/tag management)pktline.py-- Git wire protocol pkt-line framingpackfile.py-- Packfile read/write with REF_DELTA and OFS_DELTA supporttransport.py-- SSH transport:git-receive-pack(push) andgit-upload-pack(fetch) protocolremote.py-- Dispatches between local filesystem and remote SSH operationsdiff.py-- Tree diff, blob mergecli.py-- Command-line interface
python -m pytest tests/