Skip to main content

A beginner-friendly Git-like version control system

Project description

Sid โ€” A Beginner-Friendly Git-like Version Control System

๐Ÿ”ง Build your own VCS from scratch. Learn Git internals by doing.

Sid is a fully-functional version control system written in pure Python. Instead of git, you use sid. It's designed for students and beginners who want to understand how Git works under the hood.

Key Features:

  • โœ… 50 commands across 11 levels of functionality
  • โœ… Built with only Python standard libraries (no external deps)
  • โœ… Clean, commented code that explains every concept
  • โœ… Cross-platform: Windows, Linux, macOS
  • โœ… Installable CLI โ€” just run sid from anywhere

Quick Start

Installation

# Clone or download this project
cd sid

# Install in development mode
pip install -e .

# Verify installation
sid version

Your First Repository

mkdir my-project
cd my-project

# Initialize a new Sid repository
sid init

# Create a file
echo "Hello, Sid!" > hello.txt

# Check what's happening
sid status

# Stage the file
sid add hello.txt

# Commit it
sid commit -m "first commit"

# View the history
sid log

Command Reference

Level 1 โ€” Core Commands

Command Description
sid init Initialize a new .sid repository
sid add <file> Stage a file for commit
sid add . Stage all files recursively
sid commit -m "msg" Create a commit from staged files
sid status Show working tree status
sid log Show commit history
sid diff Show unstaged file differences
sid diff --staged Show staged differences

Level 2 โ€” File Restore / Reset

Command Description
sid restore <file> Restore file from index
sid restore --source HEAD <file> Restore file from last commit
sid rm <file> Remove file from tracking
sid reset Unstage all files
sid reset <file> Unstage a specific file
sid reset --hard Reset everything to HEAD โš ๏ธ

Level 3 โ€” Branching

Command Description
sid branch List all branches
sid branch <name> Create a new branch
sid branch -d <name> Delete a branch
sid checkout <branch> Switch to a branch
sid checkout -b <name> Create and switch to new branch
sid switch <branch> Switch (alias for checkout)
sid switch -c <name> Create and switch (alias)

Level 4 โ€” Commit Inspection

Command Description
sid show [ref] Show commit details
sid show HEAD Show latest commit
sid cat-file <hash> Print raw object content
sid ls-files List tracked files

Level 5 โ€” Merge

Command Description
sid merge <branch> Merge branch into current
sid merge --abort Abort in-progress merge

Level 6 โ€” Tags

Command Description
sid tag List all tags
sid tag <name> Create a lightweight tag
sid tag -d <name> Delete a tag
sid checkout <tag> Checkout tag (detached HEAD)

Level 7 โ€” Ignore File

Command Description
.sidignore Create to define ignore patterns
sid check-ignore <file> Check if a file is ignored

Level 8 โ€” Configuration

Command Description
sid config user.name "Name" Set your name
sid config user.email "email" Set your email
sid config --list Show all config entries

Level 9 โ€” Stash

Command Description
sid stash Save uncommitted changes
sid stash list Show saved stashes
sid stash apply Apply latest stash
sid stash pop Apply and remove stash

Level 10 โ€” Local Remotes

Command Description
sid remote add origin <path> Add a local remote
sid remote -v Show configured remotes
sid clone <src> <dest> Clone a repository
sid push origin main Push to remote
sid pull origin main Pull from remote

Level 11 โ€” Utilities

Command Description
sid help Show all commands
sid version Show version
sid doctor Check repository health
sid graph Show commit graph
sid clean Remove untracked files

How Sid Works Internally

The .sid Directory

When you run sid init, a hidden .sid folder is created:

.sid/
โ”œโ”€โ”€ objects/      โ† Stores file content & commits (by hash)
โ”œโ”€โ”€ refs/
โ”‚   โ”œโ”€โ”€ heads/    โ† Branch pointers (e.g., main โ†’ commit hash)
โ”‚   โ””โ”€โ”€ tags/     โ† Tag pointers
โ”œโ”€โ”€ stash/        โ† Saved stash entries
โ”œโ”€โ”€ HEAD          โ† Points to current branch
โ”œโ”€โ”€ index         โ† Staging area (JSON)
โ””โ”€โ”€ config        โ† Repository settings (JSON)

Content-Addressed Storage

Every file's content is hashed using SHA-1, producing a 40-character hex string. The content is stored in .sid/objects/<hash>. If two files have the same content, they share the same object โ€” this is called deduplication.

"Hello, World!\n"  โ†’  SHA-1  โ†’  "a0b65939670bc2c010f4d5d6a0b3e4e4590fb92b"

The Index (Staging Area)

The index at .sid/index is a JSON file mapping file paths to their blob hashes:

{
  "hello.txt": "a0b659396...",
  "src/main.py": "f3e2d1c0b..."
}

When you run sid add, the file is hashed and added here. When you run sid commit, this snapshot becomes the commit.

Commit Objects

A commit is also stored in .sid/objects/ as a JSON file:

{
  "type": "commit",
  "message": "first commit",
  "author": "Siddhant",
  "email": "sid@example.com",
  "timestamp": "2025-01-01T12:00:00+00:00",
  "parent": null,
  "files": {
    "hello.txt": "a0b659396..."
  }
}

Commits form a linked list โ€” each commit points to its parent.

Branches

A branch is just a file in .sid/refs/heads/ containing a commit hash. HEAD tells Sid which branch you're currently on:

HEAD โ†’ "ref: refs/heads/main"
refs/heads/main โ†’ "abc123..."  (commit hash)

Common Errors and Fixes

Error Fix
"not a sid repository" Run sid init first
"nothing to commit" Stage files with sid add
"cannot create branch โ€” no commits yet" Make your first commit
"cannot delete current branch" Switch to another branch first
"merge conflict" Edit the conflicted files, sid add them, then commit

Example Workflow

# Create a project
mkdir demo && cd demo
sid init
sid config user.name "Siddhant"
sid config user.email "sid@example.com"

# Create and commit files
echo "hello sid" > hello.txt
sid add hello.txt
sid commit -m "first commit"

# Make changes
echo "updated" >> hello.txt
sid diff
sid add hello.txt
sid commit -m "update hello"

# Branching
sid branch dev
sid checkout dev
echo "dev work" > dev.txt
sid add .
sid commit -m "add dev work"

# Merge
sid checkout main
sid merge dev

# Inspect
sid log
sid graph
sid show HEAD
sid doctor

Future Improvement Ideas

  • ๐Ÿ—œ๏ธ Compression โ€” Compress blob objects (zlib) to save space
  • ๐Ÿ“ฆ Binary file support โ€” Better handling of images, PDFs, etc.
  • ๐Ÿง  3-way merge โ€” Use common ancestor for smarter merging
  • ๐ŸŒ Real remote server โ€” Push/pull over HTTP or SSH
  • ๐Ÿ–ฅ๏ธ Web dashboard โ€” Browse commits and diffs in a browser
  • ๐Ÿ  GitHub-like hosting โ€” Self-hosted repository server
  • ๐Ÿ”Œ Plugin system โ€” Custom hooks and extensions
  • ๐ŸŽจ GUI app โ€” Visual interface for Sid operations
  • ๐Ÿ“Š Blame command โ€” Show who changed each line
  • ๐Ÿ” Bisect โ€” Binary search for bug-introducing commits
  • ๐Ÿ“‹ Cherry-pick โ€” Apply specific commits to another branch
  • ๐Ÿ“ Interactive rebase โ€” Rewrite commit history

Project Structure

sid/
โ”œโ”€โ”€ sid/
โ”‚   โ”œโ”€โ”€ __init__.py      # Version constant
โ”‚   โ”œโ”€โ”€ cli.py           # CLI entry point (argparse)
โ”‚   โ”œโ”€โ”€ repository.py    # Repository initialization
โ”‚   โ”œโ”€โ”€ objects.py       # Blob & commit object storage
โ”‚   โ”œโ”€โ”€ index.py         # Staging area management
โ”‚   โ”œโ”€โ”€ commit.py        # Commit creation & log
โ”‚   โ”œโ”€โ”€ status.py        # Working tree status
โ”‚   โ”œโ”€โ”€ diff.py          # Unified diff display
โ”‚   โ”œโ”€โ”€ restore.py       # File restoration
โ”‚   โ”œโ”€โ”€ reset.py         # Index/tree reset
โ”‚   โ”œโ”€โ”€ branch.py        # Branch CRUD
โ”‚   โ”œโ”€โ”€ checkout.py      # Branch/tag switching
โ”‚   โ”œโ”€โ”€ merge.py         # Branch merging
โ”‚   โ”œโ”€โ”€ tags.py          # Lightweight tags
โ”‚   โ”œโ”€โ”€ ignore.py        # .sidignore patterns
โ”‚   โ”œโ”€โ”€ config.py        # Configuration management
โ”‚   โ”œโ”€โ”€ stash.py         # Stash save/apply
โ”‚   โ”œโ”€โ”€ remote.py        # Local folder remotes
โ”‚   โ”œโ”€โ”€ graph.py         # Commit graph display
โ”‚   โ”œโ”€โ”€ clean.py         # Remove untracked files
โ”‚   โ”œโ”€โ”€ doctor.py        # Repository health check
โ”‚   โ””โ”€โ”€ utils.py         # Shared helpers
โ”œโ”€โ”€ tests/
โ”‚   โ”œโ”€โ”€ test_init.py
โ”‚   โ”œโ”€โ”€ test_add_commit.py
โ”‚   โ”œโ”€โ”€ test_branch.py
โ”‚   โ””โ”€โ”€ test_status.py
โ”œโ”€โ”€ README.md
โ”œโ”€โ”€ pyproject.toml
โ””โ”€โ”€ .sidignore.example

Running Tests

# Install dev dependencies
pip install -e ".[dev]"

# Run all tests
python -m pytest tests/ -v

# Run a specific test file
python -m pytest tests/test_init.py -v

License

MIT License โ€” Feel free to use, modify, and learn from this project.


Built with โค๏ธ for learning. Happy hacking!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sid_vcs-1.0.0.tar.gz (39.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sid_vcs-1.0.0-py3-none-any.whl (45.9 kB view details)

Uploaded Python 3

File details

Details for the file sid_vcs-1.0.0.tar.gz.

File metadata

  • Download URL: sid_vcs-1.0.0.tar.gz
  • Upload date:
  • Size: 39.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for sid_vcs-1.0.0.tar.gz
Algorithm Hash digest
SHA256 1a392c35de0755ee7e036ddbe86de03ef4d41d82acc264f770d54af74c880189
MD5 2fc5377db4e9e04ebfa350464b5da85d
BLAKE2b-256 72a130f54d2ce0344ed99832b5b8f790eded3db268bf91d1dca35d240d6a2ca4

See more details on using hashes here.

File details

Details for the file sid_vcs-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: sid_vcs-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 45.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for sid_vcs-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e004463e7af19bc6a66ba5cebb6fe78baac4fbaeb0c334f27fe67e66402ec96f
MD5 1a277e4fb6ee2f7f678326959246c9a8
BLAKE2b-256 713b89893e593af1ce4b364a1df05025fa9e417c3083f4dc87de1bfdbe0125af

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page