A Git implementation in Go for learning purposes, focused on understanding core Git concepts by building them from scratch.
Implemented Features
Repository Management
- Initialize new repository (
.gitgodirectory structure) - Repository validation and path handling
- Basic directory structure (objects, refs, etc.)
Content Storage (Blobs)
- Content-addressable storage system
- SHA-1 based content hashing
- Zlib compression
- Object storage in
.gitgo/objects
Staging Area (Index)
- File staging and unstaging
- Metadata tracking (paths, modes, timestamps)
- Binary index file format
- Staged file management
Basic Operations
gitgo init # Initialize new repository gitgo add # Add file to staging area gitgo remove # Remove file from staging gitgo checkout # switch between branches gitgo branch # list branches and show current branch gitgo branch -c # create branch gitgo branch -d # delete branch gitgo log # show commit history
Building and Running
# Build go build -o gitgo cmd/gitgo/main.go # Run ./gitgo init ./gitgo add <file>
Implementation Details
Blob Storage
- Files are stored as content-addressed blobs
- SHA-1 hash of content determines storage location
- Content is compressed using zlib
Staging Area
- Tracks files for commit
- Stores metadata in binary index format
- Handles file additions and removals
Learning Purpose
This project was built to understand Git's internal working by implementing core concepts from scratch. It focuses on:
- Content-addressable storage
- Binary file formats
- Path handling
- Object storage and compression
Key takeaways
- Understanding Git and it's internals(blobs,trees,commits)
- Binary File formats ( serialization/deserialization, byte alignment and padding)
- File system operations (path handling, file permissions,directory traversal)
- Data structures (Trees)
- Improved Golang knowledge
Notes
- This is a learning implementation
- Not intended for production use
- Implements subset of Git functionality