rit is a Git re-implementation from scartch in Rust.
The goal of this project is to learn how Git works internally by rebuilding its core concepts step by step: object storage, hashing, trees, commits, references, branches, the index, checkout, status, and diff. It follows the git source code mirror implemented originally in C at Original C source code mirror
- Initialize a repository with
.rit - Store Git-style objects using SHA-1 and zlib compression
- Support blob, tree, and commit objects
- Hash files into the object database
- Read and pretty-print objects
- Write recursive tree snapshots
- Create commits from the staging area
- Maintain
HEADand branch references - View commit history with
log - Stage files with
add - Show working tree state with
status - Switch branches and restore commits with
checkout - Protect checkout from overwriting uncommitted changes
- Remove tracked files during checkout when switching branches
- Show unstaged changes with
diff - Show staged changes with
diff --cached
rit init
rit add <file>
rit commit -m "message"
rit status
rit diff
rit diff --cached
rit log
rit branch
rit branch <name>
rit checkout <branch-or-commit>
rit hash-object <file>
rit cat-file <hash>
rit write-treeA rit repository stores its data in .rit:
.rit/
├── HEAD
├── config
├── index
├── objects/
└── refs/
└── heads/
rit follows the same core model as Git:
working tree
↓ rit add
index
↓ rit commit
commit
↓
tree
↓
blobs
Objects are stored by content hash:
content -> SHA-1 hash -> compressed object file
Branches are simple files under:
.rit/refs/heads/
HEAD points to the currently active branch.
rit init
echo "hello" > hello.txt
rit add hello.txt
rit commit -m "initial commit"
echo "second line" >> hello.txt
rit status
rit diff
rit add hello.txt
rit diff --cached
rit commit -m "update hello"
rit branch feature
rit checkout featureBuild the project:
cargo buildRun a command during development:
cargo run -- statusRun the compiled binary:
target/debug/rit status- The index uses a simple JSON format, not Git’s binary index format.
- Diff is a basic line-by-line implementation, not a full Myers diff.
- Remote operations such as clone, fetch, and push are not implemented yet.
- Merge support is not implemented yet.
- Checkout protection is conservative and blocks all untracked files.