Skip to main content

A lightweight version control system built in Python

Project description

pit-cli

╔══════════════════════════════════════════════════════════════════╗
║                                                                  ║
║    ██████╗ ██╗████████╗                                          ║
║    ██╔══██╗██║╚══██╔══╝                                          ║
║    ██████╔╝██║   ██║                                             ║
║    ██╔═══╝ ██║   ██║                                             ║
║    ██║     ██║   ██║                                             ║
║    ╚═╝     ╚═╝   ╚═╝                                             ║
║                                                                  ║
║    A lightweight version control system built in Python.         ║
║    Stage. Commit. Branch. Repeat.                                ║
║                                                                  ║
╚══════════════════════════════════════════════════════════════════╝

pit is a minimal yet functional version control system written in pure Python. It demonstrates Git-like functionality including object storage, branching, committing, and garbage collection.

Features

  • 🚀 Lightweight: No external dependencies, pure Python implementation
  • 📦 Object Storage: SHA1-based content-addressable storage system
  • 🌿 Branching: Full branch support with easy switching
  • 💾 Commits: Snapshot-based commit history
  • 🗑️ Garbage Collection: Automatic cleanup of unreachable objects
  • 🔍 Status & Log: View repository state and commit history

Installation

From PyPI (coming soon)

pip install pit-cli

From Source

git clone https://github.com/yourusername/pit-cli.git
cd pit-cli
pip install -e .

Quick Start

Initialize a repository

pit init

Add files

pit add <file_or_directory>

Commit changes

pit commit -m "Your commit message"

Create and switch branches

pit checkout -b new-feature

Switch to existing branch

pit checkout main

View commit history

pit log

Check status

pit status

List branches

pit branch

Delete a branch

pit branch -d branch-name

Run garbage collection

pit gc

Commands Reference

Command Purpose
pit init Initialize a new repository
pit add <path> Stage files/directories
pit commit -m "msg" Create a commit
pit checkout <branch> Switch to branch
pit checkout -b <branch> Create and switch branch
pit branch List branches
pit branch -d <name> Delete branch
pit status Show working tree status
pit log [-n count] Show commit history
pit gc Run garbage collection

How It Works

Core Architecture

  • Blob: Stores file content (uncompressed initially, then zlib-compressed)
  • Tree: Represents directory structure, maps filenames to blob/tree hashes
  • Commit: Captures a snapshot with tree reference, parent commits, and metadata
  • Repository: Manages the .pit/ directory structure and all operations

Object Storage

Objects are stored in .pit/objects/XX/YYYYYY... where:

  • XX = first 2 characters of SHA1 hash
  • YYYYYY... = remaining hash characters

Index & Staging

The index (.pit/index) tracks staged files:

{
  "file1.txt": "sha1hash1",
  "dir/file2.py": "sha1hash2"
}

Branches

Branches reference specific commits and are stored in .pit/refs/heads/:

.pit/refs/heads/main       → commit hash
.pit/refs/heads/feature    → commit hash

Development

Running Tests

python -m pytest tests/

Building the Package

pip install build
python -m build

Installing in Development Mode

pip install -e .

Project Structure

pit-cli/
├── pit/                    # Main package
│   └── __init__.py        # Core implementation
├── tests/                 # Unit tests
├── README.md              # This file
├── LICENSE                # MIT License
├── pyproject.toml         # Package configuration
└── main.py                # CLI entry point (legacy)

Limitations

  • No remote repositories: This is a local-only VCS
  • No merge functionality: Switching branches replaces working tree
  • No conflict resolution: Not applicable without merge
  • No file permissions: Stores only content and basic metadata
  • Single committer: No multi-user support

Contributing

Contributions are welcome! Areas for improvement:

  • Merge functionality
  • Remote repository support
  • Improved performance for large repositories
  • Better error handling and messages
  • Comprehensive test suite
  • Documentation and examples

License

This project is licensed under the MIT License - see the LICENSE file for details.

Author

Created as a learning project to understand version control systems.

See Also

  • Git - The inspiration
  • Gitlet - Similar educational project in JavaScript

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

pit_cli_ramaa-0.1.1.tar.gz (35.3 kB view details)

Uploaded Source

Built Distribution

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

pit_cli_ramaa-0.1.1-py3-none-any.whl (10.2 kB view details)

Uploaded Python 3

File details

Details for the file pit_cli_ramaa-0.1.1.tar.gz.

File metadata

  • Download URL: pit_cli_ramaa-0.1.1.tar.gz
  • Upload date:
  • Size: 35.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for pit_cli_ramaa-0.1.1.tar.gz
Algorithm Hash digest
SHA256 15e5c253f827b877f3bec5979f598ad3764a26221b6e6f3f3dc134b74fa62ce4
MD5 3eb7407d6a485a2929770ded9a41c9d3
BLAKE2b-256 582c36d48504d545d85a55434f8443a1a2dde37bb5e8df2150246f18c9706996

See more details on using hashes here.

File details

Details for the file pit_cli_ramaa-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: pit_cli_ramaa-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 10.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for pit_cli_ramaa-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ec9307fb26a6afd966a8e2a98a5b018edc47907e83d4a8567e57149fcffc1d01
MD5 54239db1f0651a45e99a409669491274
BLAKE2b-256 b73e5a7463e968a44ed60ce5c0cecced8ac785e374644d70d6006bc7434825cc

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