A memory-safe, storage-agnostic implementation of Git in Rust. No CLI calls, no libgit linkage, no host filesystem assumption.
use git_rs::{InitOptions, MemoryFileSystem, Repository};
let storage = MemoryFileSystem::new();
let repository = Repository::init(storage, "example", &InitOptions::default())?;
assert_eq!(repository.read_git_file("HEAD")?, b"ref: refs/heads/main\n");
# Ok::<(), git_rs::Error>(())cargo add git-rs
cargo run --example init -- my-repository- Abstracted storage. All data flows through the
FileSystemtrait.HostFileSystemwrites a.gitdirectory compatible with thegitCLI.MemoryFileSystemkeeps everything in process memory. Implement the trait to route objects to S3, refs to Postgres, etc. - Minimal dependencies. One production dependency:
miniz_oxidefor zlib. - Memory safe.
unsafe_code = "forbid"across the entire library. - No CLI calls. Pure Rust reimplementation — zero
gitprocess invocations. - 419 tests. 400 unit tests + 18 integration tests that compare every key
operation against the system
gitbinary byte-for-byte.
Every common Git operation is available as a library call. All tests pass, clippy is clean at pedantic level, and the crate compiles with stable Rust edition 2024.
101 runnable examples covering every operation are in
examples/. Each demonstrates a single API with minimal setup:
cargo run --example init -- my-repository
cargo run --example clone_local -- /tmp/mirror
cargo run --example receive_pack -- /tmp/bare-repo