ββββββββ βββββββ βββ ββββββββββ βββββββββββββββ
ββββββββββββββββββββ βββββββββββββββββββββββββββ
βββββββββββ ββββββ ββββββββββββββ ββββββ
βββββββββββ ββββββ ββββββββββββββ ββββββ
βββββββββββββββββββββββββββββ βββββββββββββββββββ
ββββββββ βββββββ βββββββ βββ βββ βββββββββββββββ
βββββββ βββββββ ββββ βββββββββββββββββββ βββββββ βββ
ββββββββββββββββββββββ ββββββββββββββββββββββββββββββββ
βββ βββ βββββββββ βββ βββ βββββββββββ ββββββ
βββ βββ βββββββββββββ βββ βββββββββββ ββββββ
ββββββββββββββββββββ ββββββ βββ βββ ββββββββββββββββββββ
βββββββ βββββββ βββ βββββ βββ βββ βββ βββββββ ββββββββ
A Git-like version control system implemented from scratch in Go.
SourceControl (srcc) is a ground-up implementation of the core Git object model and workflow in Go. It reproduces the fundamental mechanics of Git β content-addressed object storage, a binary staging index, branch references, and commit history β while serving as a clear, well-structured reference for how version control systems work internally.
This is not a wrapper around Git. Every component β blob/tree/commit objects, the index, reference management, and the working directory reconciler β is written from scratch.
- Core object model β blob, tree, and commit objects stored with DEFLATE compression and SHA-1 addressing
- Staging area β binary index with SHA-1 checksum integrity and O(1) entry lookup
- Branch management β create, delete, rename, and checkout branches including orphan branches and detached HEAD
- Commit history β BFS traversal of the commit DAG with configurable depth
- Working directory status β detects modified, deleted, and untracked files
- Hierarchical configuration β command-line > repo > user > system precedence
- Colored terminal output β readable, Git-familiar UI via lipgloss
- Cross-platform β Linux, macOS (Intel + ARM), Windows
- Concurrent operations β generic worker pool for parallel object processing
- Go 1.24.2 or later
git clone https://github.com/utkarsh5026/SourceControl.git
cd SourceControl/sourcecontrol
make buildThe binary is written to bin/sourcecontrol. Add it to your $PATH:
# Linux / macOS
export PATH="$PATH:$(pwd)/bin"
# Or install to $GOPATH/bin
make installmake build-all
# Produces:
# bin/sourcecontrol-linux-amd64
# bin/sourcecontrol-darwin-amd64
# bin/sourcecontrol-darwin-arm64
# bin/sourcecontrol-windows-amd64.exe# Initialize a new repository
srcc init
# Create some files
echo "Hello, world!" > hello.txt
# Stage files
srcc add hello.txt
# Commit
srcc commit -m "Initial commit"
# Check status
srcc status
# View history
srcc logInitialize a new repository. Creates a .source/ directory (analogous to .git/).
srcc init # Initialize in current directory
srcc init ./myproject # Initialize in a specific pathStage file contents to the index.
srcc add file.txt # Stage a single file
srcc add src/main.go tests/ # Stage multiple files/directoriesOutput shows added:, modified:, or failed: per file.
Create a commit from staged changes.
srcc commit -m "Fix authentication bug"Show working directory status. Displays modified, deleted, and untracked files relative to the index.
srcc statusShow commit history from HEAD.
srcc log # Detailed view, last 20 commits
srcc log -n 50 # Show last 50 commits
srcc log --table # Compact table formatList, create, delete, or rename branches.
srcc branch # List all branches
srcc branch -v # List with commit info
srcc branch feature-x # Create a branch at HEAD
srcc branch feature-x abc123 # Create a branch at a specific commit
srcc branch --start-point=main fix # Create from another branch
srcc branch -d old-branch # Delete a branch
srcc branch -D old-branch # Force delete
srcc branch -m new-name # Rename current branch
srcc branch -m old new # Rename a specific branch
srcc branch -M old new # Force renameSwitch branches or check out a commit.
srcc checkout main # Switch to existing branch
srcc checkout -b feature-x # Create and switch to new branch
srcc checkout -b new abc123 # Create branch from specific commit
srcc checkout abc123 # Detached HEAD at a commit
srcc checkout -f branch # Force (discard local changes)
srcc checkout --orphan root # New orphan branch (no parents)
srcc checkout --detach HEAD # Explicitly detach HEAD--log-level string Log level: debug, info, warn, error (default "info")
--log-format string Log format: text, json (default "text")
-v, --verbose Enable verbose output (sets log level to debug)SourceControl uses a .source/ directory at the repository root instead of .git/:
.source/
βββ objects/
β βββ ab/
β βββ cdef1234... # DEFLATE-compressed object (SHA-1 addressed)
βββ refs/
β βββ heads/
β βββ main # Plain-text SHA-1 of branch tip
βββ HEAD # "ref: refs/heads/main" or bare SHA-1
βββ index # Binary staging area with SHA-1 checksum
All stored data is one of three object types, mirroring Git's model:
| Type | Description |
|---|---|
blob |
Raw file content |
tree |
Directory listing (name + mode + object hash per entry) |
commit |
Snapshot: tree hash, parent hashes, author/committer, message |
Objects are serialized as <type> <size>\0<content>, DEFLATE-compressed, and stored at a path derived from their SHA-1 hash.
pkg/
βββ objects/ # Object types and serialization
βββ index/ # Staging area (binary format, O(1) entryMap)
βββ store/ # File-based object store
βββ commitmanager/ # Commit creation + BFS history traversal
βββ refs/branch/ # Branch and HEAD management
βββ workdir/ # Working directory reconciler
βββ config/ # Hierarchical configuration
βββ repository/ # Repository interface, path types, .gitignore
βββ common/
βββ err/ # Typed error system
βββ fileops/ # Atomic file writes
βββ logger/ # slog-based structured logging
βββ concurrency/ # Generic worker pool
All commands run from the sourcecontrol/ directory.
make test # All tests with race detection + coverage
make test-coverage # Tests + generate coverage.html
make bench # Benchmarks
# Specific package
go test -v -race ./pkg/index/...make fmt # Format with gofmt
make lint # golangci-lint (falls back to go vet)- Unit tests β per-package, table-driven with
t.Run() - Integration tests β full init β add β commit β branch workflows (
integration_test.go,integration_complex_test.go) - Compatibility tests β compare output against real Git (
git_compat_test.go)
| Package | Purpose |
|---|---|
spf13/cobra |
CLI framework |
charmbracelet/lipgloss |
Terminal styling |
olekukonko/tablewriter |
Table output |
stretchr/testify |
Test assertions |
golang.org/x/sync |
errgroup for concurrent ops |
- Fork the repository
- Create a feature branch:
git checkout -b feature/your-feature - Make your changes, ensuring
make testandmake lintpass - Run
make fmtto format code before committing - Submit a pull request
See CHANGELOG.md for version history.