A minimal Git implementation in Python
Project description
ugit ๐
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
- Installation Guide - How to install and set up ugit
- User Guide - Complete guide to using ugit commands
- Examples - Practical examples and use cases
- API Reference - Technical documentation
- Developer Guide - Guide for contributors
- Architecture - System design overview
- FAQ - Frequently asked questions
- Troubleshooting - Common issues and solutions
๏ฟฝ๐ 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
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Make your changes
- Add tests for new functionality
- Ensure all tests pass (
pytest) - Format your code (
black .andisort .) - Commit your changes (
git commit -m 'Add amazing feature') - Push to your branch (
git push origin feature/amazing-feature) - 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
90ba547234eadb19cff3937b93b665fc37215b9409385e642b831593f0d206a9
|
|
| MD5 |
bb280a4a322ea2df0f7eef6c78c12345
|
|
| BLAKE2b-256 |
64754bc6a268564294d1c51e131af470454306693cc0c6b63bcff8560fde0a18
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a811462dfb1f88b90558f96e7ca8da6d4ffdbd76dfd1e0059c15bfb1f80426d3
|
|
| MD5 |
31fd64621af70d03126beb6b22f361f2
|
|
| BLAKE2b-256 |
9d96f83f41fd8b98ea60a17ca0f578515354b8898fe46957d987a848b3d65679
|