Skip to content

vajradevam/pit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pit - a Git implementation in Python

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.

Install

pip install -e .

This makes the pit command available globally.

Quick start

pit init
echo "hello" > readme.txt
pit add readme.txt
pit commit -m "first commit"

Author identity

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):

  1. GIT_AUTHOR_NAME / GIT_AUTHOR_EMAIL env vars
  2. GIT_COMMITTER_NAME / GIT_COMMITTER_EMAIL env vars
  3. ~/.gitconfig [user] name / email
  4. Error with instructions to configure it

Commands

Local

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)

Remotes

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 master

Or use a URL directly:

pit push git@github.com:user/repo.git master

What makes pit different

Everything 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 framing
  • packfile.py -- Packfile read/write with REF_DELTA and OFS_DELTA support
  • transport.py -- SSH transport: git-receive-pack (push) and git-upload-pack (fetch) protocol
  • remote.py -- Dispatches between local filesystem and remote SSH operations
  • diff.py -- Tree diff, blob merge
  • cli.py -- Command-line interface

Tests

python -m pytest tests/

About

Git implementation in python

Resources

License

Stars

Watchers

Forks

Contributors

Languages