Skip to main content

A minimal git implementation that fits in your pocket

Project description

🎒 Pocket-Git

A minimal git implementation that fits in your pocket!

PyPI version Python 3.8+ License: MIT

🚀 Quick Start

# Install
pip install pocket-git

# Use it!
pocket-git init
pocket-git add myfile.txt
pocket-git commit "My first commit"
pocket-git log

Or use the shorter alias:

pgit init
pgit add myfile.txt
pgit commit "First commit"

✨ Features

  • init - Initialize repository
  • add - Stage files for commit
  • commit - Create snapshots of your project
  • log - View commit history
  • status - Check what's staged

📚 What You'll Learn

Pocket-Git implements the core concepts that make git work:

Content-Addressable Storage

Every file is stored as a "blob" object, identified by its SHA-1 hash. Same content = same hash = stored once!

The Three Trees

  1. Working Directory - Your actual files
  2. Staging Area (Index) - Files prepared for commit
  3. Repository (.pocket-git/) - Committed snapshots

Object Model

  • Blobs - File contents
  • Trees - Directory structures
  • Commits - Snapshots with metadata and parent links

DAG (Directed Acyclic Graph)

Commits form a chain, each pointing to its parent, creating your project's history.

🔍 How It Works

# When you run 'pocket-git add file.txt':
1. File content is read
2. SHA-1 hash is calculated
3. Content is compressed and stored in .pocket-git/objects/
4. Filename  hash mapping added to staging area

# When you run 'pocket-git commit "message"':
1. Tree object created from staging area
2. Commit object created with:
   - Reference to tree
   - Parent commit
   - Author and timestamp
   - Your message
3. Branch reference updated to point to new commit

📖 Tutorial

Initialize a Repository

mkdir my-project
cd my-project
pocket-git init

This creates .pocket-git/ with:

  • objects/ - where all content is stored
  • refs/heads/ - branch pointers
  • HEAD - points to current branch
  • index - staging area

Make Your First Commit

echo "Hello World" > hello.txt
pocket-git add hello.txt
pocket-git status
pocket-git commit "Add hello.txt"

View History

pocket-git log

Explore the Internals

# See the objects created
ls -la .pocket-git/objects/

# Objects are named by their hash
# Try decompressing one to see the content!

🛠️ Development

# Clone the repo
git clone https://github.com/yourusername/pocket-git.git
cd pocket-git

# Install in development mode
pip install -e .

# Run tests
python -m pytest tests/

# Make changes and test
pgit init
pgit add test.txt
pgit commit "Testing my changes"

🤝 Contributing

Contributions welcome! This is a learning project, so:

  • Keep code simple and well-commented
  • Explain why, not just what
  • Add tests for new features
  • Update documentation

⭐ Star this repo if you learned something new!

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

pocket_git-0.1.1.tar.gz (5.5 kB view details)

Uploaded Source

Built Distribution

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

pocket_git-0.1.1-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for pocket_git-0.1.1.tar.gz
Algorithm Hash digest
SHA256 916031fef3eaf1607c61e50e25c9e9b94f341d96a04c4b688e6b6e5b3040b20e
MD5 109e788ad1980617dbef6ca149ca9f59
BLAKE2b-256 818f45c064ce50e49cf56287ebffd20a3011d16abbe9bf6f6d1ad6c0e1bc6bcf

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for pocket_git-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a0318858025611f15e116808768d03c9e65dcc533263671d8410ae20d1d065d6
MD5 98468a2ebd4031742bfc3036979089ab
BLAKE2b-256 f78f985034786e48344e7ac5e7e92f953f20c96b93173d8ce8f140245d59c9fd

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