A complete, educational implementation of Git version control system written in Rust. Mini Git demonstrates Git's core concepts and internal workings through local repository operations, making it perfect for understanding how Git really works under the hood.
Mini Git is intentionally designed for local operations only. This design choice allows you to:
- π§ Learn Git internals without network protocol complexity
- π See exactly how Git works with object stores, trees, and commits
- ποΈ Understand distributed concepts through local repository simulation
- π Master Git fundamentals before tackling network implementations
- Repository Management:
init,clone(local paths) - Version Control:
add,commit,status,log,diff - Branching & Merging:
branch,checkout,mergewith conflict detection - Local Remotes:
push/pullbetween local repositories - Stashing:
stash push/pop/list/show/drop/clear - Remote Management: Add/manage local repository references
- SHA-1 content addressing
- Zlib-compressed objects
- Tree and blob management
- Complete commit history
- β GitHub/GitLab:
https://github.com/user/repo.git - β SSH Remotes:
git@github.com:user/repo.git - β HTTP/HTTPS: Any network-based remote URLs
- β Git Protocols:
git://protocol support
For network operations, use standard Git alongside Mini Git.
git clone https://github.com/AarambhDevHub/mini-git.git
cd mini_git
cargo build --release# Initialize a repository
./target/release/mini_git init
# Add and commit files
echo "Hello, Mini Git!" > hello.txt
./target/release/mini_git add .
./target/release/mini_git commit -m "First commit" --author "You <you@example.com>"
# View history
./target/release/mini_git log
./target/release/mini_git statusβββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Mini Git Architecture β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β User Interface β β Commands β β Core Engine β
β β β β β β
β ββββββββββββββββ β ββββββββββββββββ β ββββββββββββββββ
β β CLI βββββββ€ β init ββ β β Object Storeββ
β β (clap) ββ β β add ββ β β (SHA-1) ββ
β ββββββββββββββββ β β commit ββ β ββββββββββββββββ
β β β β status ββ β β
β ββββββββββββββββ β β log ββ β ββββββββββββββββ
β β Subcommands ββ β β branch βββββββ€ β Repository ββ
β β Parser ββ β β checkout ββ β β Utils ββ
β ββββββββββββββββ β β merge ββ β ββββββββββββββββ
βββββββββββββββββββ β β clone ββ β β
β β push ββ β ββββββββββββββββ
β β pull ββ β β Index ββ
β β remote ββ β β Management ββ
β β stash ββ β ββββββββββββββββ
β β diff ββ βββββββββββββββββββ
β ββββββββββββββββ
βββββββββββββββββββ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Data Flow Architecture β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Working Directory Index (Staging) Object Database References
βββββββββββββββββ βββββββββββββββ βββββββββββββββ ββββββββββ
βββββββββββββββ βββββββββββββββ βββββββββββββββ βββββββββββ
β file1.txt β β Staged β β Objects β β HEAD β
β file2.py β βββββΊ β Changes β ββββΊ β β ββββΊ β β
β README.md β add β βcommitβ βββββββββββ β β refs/ β
β ... β β JSON Index β β β Blob β β β heads/ β
βββββββββββββββ β Format β β β Tree β β β main β
βββββββββββββββ β β Commit β β β feature β
β βββββββββββ β βββββββββββ
βββββββββββββββ β β
β Stash β β Compressed β βββββββββββ
β Storage β ββββΊ β (zlib) β β Remote β
β β β SHA-1 Hash β β Trackingβ
βββββββββββββββ βββββββββββββββ βββββββββββ
.mini_git/
βββ objects/ # Git Object Database
β βββ 12/ # Directory: First 2 chars of SHA-1
β β βββ 3456789abcdef... # File: Remaining 38 chars (zlib compressed)
β βββ ab/
β β βββ cdef1234567... # Blob object (file content)
β β βββ 9876543210a... # Tree object (directory structure)
β βββ de/
β βββ f123456789b... # Commit object (snapshot + metadata)
β
βββ refs/ # Reference Storage
β βββ heads/ # Local branch pointers
β β βββ main # Points to commit SHA-1
β β βββ feature # Points to commit SHA-1
β βββ remotes/ # Remote tracking branches
β βββ origin/ # Remote named 'origin'
β βββ main # Tracks remote main branch
β βββ feature # Tracks remote feature branch
β
βββ index # Staging Area (JSON format)
βββ HEAD # Current branch pointer
βββ config # Repository configuration
βββ stash # Stashed changes (JSON array)
Commit Object Tree Object Blob Object
βββββββββββββ βββββββββββββ βββββββββββββ
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββ
β hash: abc123... β β hash: def456... β β hash: 789xyzβ
β parent: xyz789..β βββββββββΊβ entries: { β βββββββΊ β content: β
β tree: def456... β β "file.txt": { β β "Hello\n" β
β author: "Name" β β mode: "644" β β β
β message: "Fix" β β hash: 789xyzβ β β
β timestamp: ... β β is_file: T β β β
βββββββββββββββββββ β }, β βββββββββββββββ
β β "src/": { β
β β mode: "040" β βββββββββββββββ
β β hash: sub123ββββββββββΊβ hash: sub123β
βββββΊ Parent β is_file: F β β entries: { β
Commit β } β β "main.rs" β
β } β β ... β
βββββββββββββββββββ βββββββββββββββ
β
βββββββββββββββββββ
β Subdirectory β
β Tree Object β
βββββββββββββββββββ
User Input β CLI Parser β Command Router β Core Operations β Storage
βββββββββββββββ βββββββββββββββ βββββββββββββββ βββββββββββββββ
β mini_git β β Clap β β Command β β Object β
β add file.txtββββΊβ Parser ββββΊβ Executor ββββΊβ Store β
βββββββββββββββ βββββββββββββββ βββββββββββββββ βββββββββββββββ
β
Example Flow: βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
1. add file.txt β Command Processing β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
βΌ β
2. Parse args βββββββββββββββ βΌ βββββββββββββββ
β β Read File β βββββββββββββββ β Update β
βΌ β Content βββββΊβ Calculate ββΊβ Index β
3. Load file βββββββββββββββ β SHA-1 Hash β β (Staging) β
β βββββββββββββββ βββββββββββββββ
βΌ β
4. Hash content βββββββββββββββ βΌ βββββββββββββββ
β β Compress β βββββββββββββββ β Success β
βΌ β with zlib βββββΊβ Store Blob βββΊβ Message β
5. Store object βββββββββββββββ β Object β βββββββββββββββ
β βββββββββββββββ
βΌ
6. Update index
# Start a project
mkdir my_project && cd my_project
mini_git init
# Create files and track changes
echo "# My Project" > README.md
echo "fn main() { println!(\"Hello!\"); }" > main.rs
mini_git add .
mini_git commit -m "Initial commit"
# Check project state
mini_git status
mini_git log# Create feature branch
mini_git branch feature-auth
mini_git checkout feature-auth
# Develop feature
echo "Authentication module" > auth.rs
mini_git add auth.rs
mini_git commit -m "Add authentication"
# Merge back to main
mini_git checkout main
mini_git merge feature-auth
mini_git branch feature-auth --delete# Create "central" repository
mkdir team_project && cd team_project
mini_git init
echo "Team Project" > README.md
mini_git add . && mini_git commit -m "Project start"
# Developer A
cd .. && mini_git clone team_project dev_alice
cd dev_alice
echo "Alice's feature" > feature_a.py
mini_git add . && mini_git commit -m "Add feature A"
mini_git push origin main
# Developer B
cd .. && mini_git clone team_project dev_bob
cd dev_bob
mini_git pull origin main # Gets Alice's changes
echo "Bob's feature" > feature_b.py
mini_git add . && mini_git commit -m "Add feature B"
mini_git push origin main
# Alice syncs latest changes
cd ../dev_alice
mini_git pull origin main
ls # See both features: feature_a.py, feature_b.py# Working on something...
echo "Work in progress..." > unfinished.txt
mini_git add unfinished.txt
# Need to switch context quickly
mini_git stash push -m "WIP: new feature"
mini_git checkout other-branch
# Later, restore work
mini_git checkout main
mini_git stash pop # Restores unfinished.txt
# Or manage multiple stashes
mini_git stash list
mini_git stash show 0
mini_git stash drop 0mini_git init # Initialize repository
mini_git clone <local_path> <dir> # Clone local repository
mini_git status # Show working directory statusmini_git add <files> # Stage files
mini_git add . # Stage all files
mini_git commit -m "message" # Create commit
mini_git commit -m "msg" --author "Name <email>" # With authormini_git log # Show commit history
mini_git log --max-count 5 # Limit number of commits
mini_git diff # Show unstaged changes
mini_git diff <files> # Diff specific filesmini_git branch # List branches
mini_git branch <name> # Create branch
mini_git branch <name> --delete # Delete branch
mini_git checkout <branch> # Switch branches
mini_git merge <branch> # Merge branch into currentmini_git remote # List remotes
mini_git remote -v # List with URLs
mini_git remote add <name> <local_path> # Add local remote
mini_git remote remove <name> # Remove remote
mini_git remote set-url <name> <path> # Change remote URL
mini_git push <remote> <branch> # Push to local remote
mini_git pull <remote> <branch> # Pull from local remotemini_git stash # Stash current changes
mini_git stash push -m "message" # Stash with message
mini_git stash list # List all stashes
mini_git stash show # Show latest stash
mini_git stash pop # Apply and remove latest stash
mini_git stash drop # Delete a stash
mini_git stash clear # Delete all stasheschmod +x test_minigit.sh
./test_minigit.shTests cover:
- β Basic repository operations
- β Branching and merging
- β Local clone/push/pull workflows
- β Stash functionality
- β Remote management
- β Object store integrity
- β Error handling
# Quick functionality test
mkdir test && cd test
mini_git init
echo "test" > file.txt
mini_git add . && mini_git commit -m "test"
mini_git logSince Mini Git is local-only, here's how to work with GitHub/GitLab:
# Develop with Mini Git
mini_git add . && mini_git commit -m "Feature complete"
# Publish with standard Git
git init # Initialize Git in same directory
git remote add origin https://github.com/user/repo.git
git add . && git commit -m "Feature complete"
git push origin main# Use Mini Git for local development and learning
mini_git branch feature && mini_git checkout feature
mini_git add . && mini_git commit -m "Local development"
# Use Git for collaboration
git checkout main && git pull origin main
git merge feature && git push origin mainmini_git/
βββ src/
β βββ main.rs # CLI interface
β βββ lib.rs # Core types
β βββ object_store.rs # Git object storage
β βββ utils.rs # Repository utilities
β βββ commands/ # Command implementations
β βββ init.rs # Repository initialization
β βββ add.rs # Staging operations
β βββ commit.rs # Commit creation
β βββ status.rs # Working directory status
β βββ log.rs # History viewing
β βββ branch.rs # Branch management
β βββ checkout.rs # Branch switching
β βββ merge.rs # Three-way merge
β βββ diff.rs # File differences
β βββ clone.rs # Local cloning
β βββ push.rs # Local push operations
β βββ pull.rs # Local pull operations
β βββ remote.rs # Remote management
β βββ stash.rs # Stash operations
βββ Cargo.toml # Dependencies
βββ test_minigit.sh # Test suite
βββ README.md # This file
By using Mini Git, you'll understand:
- Git Object Model: How commits, trees, and blobs work
- Content Addressing: Why Git uses SHA-1 hashes
- Distributed Architecture: How multiple repositories sync
- Merge Algorithms: Three-way merge and conflict resolution
- Index Mechanics: How the staging area works
- Reference Management: Branches, tags, and HEAD
- Data Integrity: How Git ensures data consistency
[dependencies]
sha1 = "0.10" # SHA-1 hashing for content addressing
serde = "1.0" # Serialization framework
serde_json = "1.0" # JSON support for objects
chrono = "0.4" # Date and time handling
clap = "4.0" # Command-line argument parsing
walkdir = "2.3" # Directory tree traversal
flate2 = "1.0" # Zlib compression for objects- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Write tests for your changes
- Ensure all tests pass (
./test_minigit.sh) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- Pro Git Book - Complete Git reference
- Git Internals - How Git works internally
- Building Git - Git implementation guide
MIT License - see LICENSE file for details.
If you find Ignitia helpful, consider supporting the project:
- Git community for excellent design and documentation
- Rust community for amazing development tools
- Educational Git resources that inspired this implementation
Made with β€οΈ and π¦ Rust β€οΈ by Aarambh Dev Hub
π― Mini Git: Learn Git by building Git, one commit at a time!
Perfect for students, developers, and anyone curious about how Git really works under the hood.