Skip to main content

A minimal Git implementation in Python

Project description

ugit ๐Ÿš€

Python 3.9+ License: MIT Code style: black

A minimal Git implementation in Python that demonstrates the core concepts of version control systems. Perfect for learning how Git works under the hood!

โœจ Features

Core Git Functionality

  • Repository initialization - Create new ugit repositories
  • File staging - Add files to the staging area
  • Committing - Create commits from staged changes
  • History viewing - Browse commit history with detailed logs
  • Checkout - Restore files from specific commits
  • Status checking - See which files are modified, staged, or untracked
  • Branching - Create, switch, and manage branches
  • Merging - Merge branches with conflict resolution
  • Remotes - Work with remote repositories (clone, fetch, pull, push)
  • Stashing - Temporarily save changes for later (save, list, pop, apply, drop)
  • Diffing - Compare changes between commits, files, or working directory

๐ŸŒ Web Interface

  • Beautiful Dark Mode Interface - Modern, professional repository browser
  • File Explorer - Navigate repository files and directories with ease
  • Code Viewer - Syntax-highlighted file viewing with line numbers
  • Commit History - Visual commit timeline with detailed information
  • Real-time Updates - Dynamic loading of repository data
  • Responsive Design - Works perfectly on desktop and mobile devices

๏ฟฝ Documentation

๏ฟฝ๐Ÿš€ Quick Start

Installation Options

Option 1: Basic Installation (CLI Only)

pip install ugit

This installs the core ugit functionality for command-line usage.

Option 2: Full Installation (CLI + Web Interface)

pip install ugit[web]

This includes the beautiful web interface for browsing repositories.

Option 3: Development Installation

# Clone the repository
git clone https://github.com/night-slayer18/ugit.git
cd ugit

# Install in development mode (CLI only)
pip install -e .

# Or install with web interface support
pip install -e .[web]

pip install -e .[web]


### Basic Usage

#### Command Line Interface
```bash
# Initialize a new repository
ugit init

# Add files to staging area
ugit add file.txt
ugit add .

# Create a commit
ugit commit -m "Initial commit"
ugit commit -m "Commit message" --author "Name <email@example.com>"

# Check repository status
ugit status

# View commit history
ugit log                    # Full history
ugit log --oneline         # Compact view
ugit log --graph           # ASCII graph
ugit log -n 5              # Limit to 5 commits
ugit log --since "2025-01-01"  # Since date

# Checkout commits and branches
ugit checkout <commit-sha>  # Checkout specific commit
ugit checkout <branch>      # Switch to branch
ugit checkout -b <branch>   # Create and switch to branch

# Branch management
ugit branch                 # List branches
ugit branch <name>          # Create branch
ugit branch -d <name>       # Delete branch

# Merge branches
ugit merge <branch>         # Merge branch
ugit merge <branch> --no-ff # Force merge commit

# Show differences
ugit diff                   # Working directory changes
ugit diff --staged          # Staged changes
ugit diff <commit1> <commit2>  # Between commits

# Reset operations
ugit reset                  # Unstage all files
ugit reset <commit>         # Reset to commit (soft)
ugit reset --hard <commit>  # Reset to commit (hard)
ugit reset --soft <commit>  # Reset to commit (keep staged)

# Stash operations
ugit stash                  # Stash current changes
ugit stash save "message"   # Stash with message
ugit stash list             # List all stashes
ugit stash pop              # Apply and remove latest stash
ugit stash pop 1            # Apply specific stash by index
ugit stash apply            # Apply stash without removing
ugit stash drop             # Remove stash without applying
ugit stash -u               # Include untracked files

# Remote repository operations
ugit clone <url> [directory]     # Clone repository
ugit remote                      # List remotes
ugit remote -v                   # List remotes with URLs
ugit remote add origin <url>     # Add remote
ugit remote remove <name>        # Remove remote
ugit remote show <name>          # Show remote details

# Fetch, pull, and push
ugit fetch                       # Fetch from origin
ugit fetch <remote>              # Fetch from specific remote
ugit pull                        # Pull from origin/current branch
ugit pull <remote> <branch>      # Pull specific branch
ugit push                        # Push to origin/current branch
ugit push <remote> <branch>      # Push specific branch
ugit push -f                     # Force push

# Configuration
ugit config user.name "Your Name"
ugit config user.email "you@example.com"
ugit config --list           # List all configuration

๐ŸŒ Web Interface

# Start the web interface (requires ugit[web] installation)
ugit serve

# Custom host and port
ugit serve --host 0.0.0.0 --port 8080

# Don't open browser automatically
ugit serve --no-browser

The web interface provides:

  • Beautiful file browser with syntax highlighting
  • Interactive commit history with timeline view
  • Responsive design that works on all devices
  • Real-time repository exploration without command line

๐Ÿ“ Project Structure

ugit/
โ”œโ”€โ”€ ugit/                   # Main package
โ”‚   โ”œโ”€โ”€ __init__.py        # Package initialization
โ”‚   โ”œโ”€โ”€ cli.py             # Command-line interface
โ”‚   โ”œโ”€โ”€ core/              # Core functionality
โ”‚   โ”‚   โ”œโ”€โ”€ objects.py     # Object storage and hashing
โ”‚   โ”‚   โ””โ”€โ”€ repository.py  # Repository and index management
โ”‚   โ”œโ”€โ”€ commands/          # Command implementations
โ”‚   โ”‚   โ”œโ”€โ”€ init.py        # Repository initialization
โ”‚   โ”‚   โ”œโ”€โ”€ add.py         # File staging
โ”‚   โ”‚   โ”œโ”€โ”€ commit.py      # Commit creation
โ”‚   โ”‚   โ”œโ”€โ”€ log.py         # History viewing
โ”‚   โ”‚   โ”œโ”€โ”€ checkout.py    # File restoration
โ”‚   โ”‚   โ”œโ”€โ”€ status.py      # Status checking
โ”‚   โ”‚   โ”œโ”€โ”€ serve.py       # Web interface server
โ”‚   โ”‚   โ”œโ”€โ”€ branch.py      # Branch management
โ”‚   โ”‚   โ”œโ”€โ”€ merge.py       # Branch merging
โ”‚   โ”‚   โ”œโ”€โ”€ remote.py      # Remote repositories
โ”‚   โ”‚   โ”œโ”€โ”€ clone.py       # Repository cloning
โ”‚   โ”‚   โ”œโ”€โ”€ fetch.py       # Fetch from remotes
โ”‚   โ”‚   โ”œโ”€โ”€ pull.py        # Pull changes
โ”‚   โ”‚   โ”œโ”€โ”€ push.py        # Push changes
โ”‚   โ”‚   โ”œโ”€โ”€ stash.py       # Stash management
โ”‚   โ”‚   โ”œโ”€โ”€ reset.py       # Reset operations
โ”‚   โ”‚   โ”œโ”€โ”€ diff.py        # Show differences
โ”‚   โ”‚   โ””โ”€โ”€ config.py      # Configuration management
โ”‚   โ”œโ”€โ”€ web/               # Web interface components
โ”‚   โ”‚   โ”œโ”€โ”€ server.py      # FastAPI web server
โ”‚   โ”‚   โ”œโ”€โ”€ templates/     # HTML templates
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ index.html # Main interface template
โ”‚   โ”‚   โ””โ”€โ”€ static/        # Static assets
โ”‚   โ”‚       โ”œโ”€โ”€ css/       # Stylesheets
โ”‚   โ”‚       โ”‚   โ””โ”€โ”€ style.css  # Main dark theme styles
โ”‚   โ”‚       โ””โ”€โ”€ js/        # JavaScript files
โ”‚   โ”‚           โ””โ”€โ”€ app.js     # Frontend application logic
โ”‚   โ””โ”€โ”€ utils/             # Utility functions
โ”œโ”€โ”€ tests/                 # Unit tests
โ”œโ”€โ”€ docs/                  # Documentation
โ”œโ”€โ”€ pyproject.toml        # Project configuration
โ”œโ”€โ”€ requirements.txt      # Basic dependencies
โ”œโ”€โ”€ web-requirements.txt  # Web interface dependencies
โ””โ”€โ”€ README.md            # This file

๐Ÿ”ง How It Works

ugit implements the core Git concepts:

Object Storage

  • Blobs: Store file contents
  • Trees: Store directory structures
  • Commits: Store snapshots with metadata
  • Objects are stored by SHA-1 hash in .ugit/objects/

Repository Structure

.ugit/
โ”œโ”€โ”€ objects/           # Object storage (blobs, trees, commits)
โ”œโ”€โ”€ refs/heads/        # Branch references
โ”œโ”€โ”€ HEAD              # Current branch pointer
โ””โ”€โ”€ index             # Staging area

Commands

Command Description Example
init Initialize repository ugit init
add Stage files ugit add file.txt
commit Create commit ugit commit -m "message"
status Show status ugit status
config Configuration ugit config user.name "John"
log Show history ugit log --oneline --graph
checkout Restore files/switch branches ugit checkout -b feature
branch Manage branches ugit branch -d old-feature
merge Merge branches ugit merge feature --no-ff
diff Show changes ugit diff --staged
reset Reset changes ugit reset --hard HEAD~1
stash Temporarily save changes ugit stash save "WIP"
stash list List all stashes ugit stash list
stash pop Apply and remove stash ugit stash pop 1
stash apply Apply stash (keep it) ugit stash apply
stash drop Remove stash ugit stash drop 0
clone Clone repository ugit clone <url>
remote Manage remotes ugit remote add origin <url>
fetch Fetch from remote ugit fetch origin
pull Pull changes ugit pull origin main
push Push changes ugit push -f origin main
serve Start web interface ugit serve --port 8080

๐Ÿงช Development

Setup Development Environment

# Clone and install in development mode
git clone https://github.com/night-slayer18/ugit.git
cd ugit
pip install -e .[dev]

# Install pre-commit hooks
pre-commit install

Running Tests

# Run all tests
pytest

# Run with coverage
pytest --cov=ugit

# Run specific test file
pytest tests/test_commands.py

Code Quality

# Format code
black ugit/ tests/

# Sort imports  
isort ugit/ tests/

# Type checking
mypy ugit/

# Linting
flake8 ugit/ tests/

๐Ÿค Contributing

We welcome contributions! Please see CONTRIBUTING.md for guidelines.

Quick Contribution Guide

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Make your changes
  4. Add tests for new functionality
  5. Ensure all tests pass (pytest)
  6. Format your code (black . and isort .)
  7. Commit your changes (git commit -m 'Add amazing feature')
  8. Push to your branch (git push origin feature/amazing-feature)
  9. Open a Pull Request

๐Ÿ“š Learning Resources

๐Ÿ“„ License

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

๐Ÿ™ Acknowledgments

  • Inspired by the excellent Git internals documentation
  • Built for educational purposes to understand version control systems
  • Thanks to all contributors who help improve this project

๐Ÿ“ž Support

  • ๐Ÿ“ซ Create an issue for bug reports or feature requests
  • ๐Ÿ’ฌ Start a discussion for questions
  • โญ Star this repository if you find it helpful!

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

ugit_cli-1.2.0.tar.gz (70.3 kB view details)

Uploaded Source

Built Distribution

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

ugit_cli-1.2.0-py3-none-any.whl (69.8 kB view details)

Uploaded Python 3

File details

Details for the file ugit_cli-1.2.0.tar.gz.

File metadata

  • Download URL: ugit_cli-1.2.0.tar.gz
  • Upload date:
  • Size: 70.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for ugit_cli-1.2.0.tar.gz
Algorithm Hash digest
SHA256 90ba547234eadb19cff3937b93b665fc37215b9409385e642b831593f0d206a9
MD5 bb280a4a322ea2df0f7eef6c78c12345
BLAKE2b-256 64754bc6a268564294d1c51e131af470454306693cc0c6b63bcff8560fde0a18

See more details on using hashes here.

File details

Details for the file ugit_cli-1.2.0-py3-none-any.whl.

File metadata

  • Download URL: ugit_cli-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 69.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for ugit_cli-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a811462dfb1f88b90558f96e7ca8da6d4ffdbd76dfd1e0059c15bfb1f80426d3
MD5 31fd64621af70d03126beb6b22f361f2
BLAKE2b-256 9d96f83f41fd8b98ea60a17ca0f578515354b8898fe46957d987a848b3d65679

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