AI-powered git commit message generator and git utility toolkit
Project description
smartgit
AI-powered git commit message generator and intelligent git utility toolkit
Package:
smart-git-ai| Command:smartgit
Never write commit messages manually again. Let Claude AI understand your changes and generate meaningful, conventional commit messages.
Features • Installation • Quick Start • Documentation • Contributing
Table of Contents
- Why smartgit?
- Features
- Installation
- Quick Start
- Usage
- Configuration Files
- Commit Message Format
- Examples
- Requirements
- Development
- Documentation
- Contributing
- License
Why smartgit?
Writing good commit messages is hard and time-consuming. smartgit solves this by:
- Understanding your code changes using Claude AI to analyze diffs
- Following best practices automatically with Conventional Commits format
- Saving time by generating messages in seconds
- Maintaining consistency across your entire team
- Providing helpful utilities to manage your git workflow
Features
🤖 AI-Powered Commit Messages
- Intelligent Analysis: Claude AI reads your staged changes and understands context
- Conventional Commits: Automatically formatted with proper type, scope, and description
- Multiple Providers: Support for Anthropic Claude and OpenAI models
- Customizable: Add context, configure styles, and adjust behavior
🔗 Seamless Git Integration
- Git Hooks: Install
prepare-commit-msghook for automatic message generation - Native Workflow: Works with standard
git commitcommands - Editor Support: Opens your default git editor for review and editing
- Safe and Reversible: Easy to install/uninstall hooks with backups
🛠️ Powerful Git Utilities
When you need more than commits, smartgit provides helpful utilities:
| Utility | Description |
|---|---|
undo |
Safely undo last commit (keep or discard changes) |
cleanup |
Remove local branches that have been merged |
stale |
Find branches not updated in N days |
large-files |
Locate files above size threshold |
suggest-gitignore |
Auto-suggest .gitignore entries for untracked files |
force-push-safe |
Force push with lease to prevent overwriting |
fixup |
Create fixup commits for autosquashing |
worktree |
Manage git worktrees for parallel development |
Installation
From PyPI (Recommended)
pip install smart-git-ai
From Source
git clone https://github.com/SifatIbna/smart-git-ai.git
cd smart-git-ai
pip install -e .
Verify Installation
smartgit --version
Quick Start
1️⃣ Set up your API key
Get your API key from Anthropic Console:
# Add to your shell profile (~/.bashrc, ~/.zshrc, etc.)
export ANTHROPIC_API_KEY="your_api_key_here"
# Or create a .env file in your project
echo "ANTHROPIC_API_KEY=your_api_key_here" > .env
2️⃣ Generate your first AI commit
# Stage your changes
git add .
# Generate and commit with AI
smartgit generate
# Or preview without committing
smartgit generate --dry-run
3️⃣ Install git hooks (optional but recommended)
# Install prepare-commit-msg hook
smartgit install
# Now regular git commit will use AI automatically
git commit
That's it! 🎉 You're now using AI-powered commit messages.
Usage
Generate Commit Messages
# Generate AI commit message for staged changes
smartgit generate
# Add context to help the AI understand your changes
smartgit generate --context "Refactored authentication to use JWT"
# Preview without committing
smartgit generate --dry-run
# Skip editor confirmation and commit immediately
smartgit generate --no-edit
Git Hooks Integration
# Install hooks
smartgit install
# Install with force (overwrite existing hooks)
smartgit install --force
# Check installation status
smartgit status
# Uninstall hooks
smartgit uninstall
# Uninstall and restore previous backup
smartgit uninstall --restore
Git Utilities
# Undo last commit (keep changes staged)
smartgit utils undo
# Undo last commit and discard changes
smartgit utils undo --hard
# Clean up merged branches
smartgit utils cleanup
# Find stale branches (not updated in 30 days)
smartgit utils stale
smartgit utils stale --days 60
# Find large files (>10MB)
smartgit utils large-files
smartgit utils large-files --size 5.0
# Suggest .gitignore entries for untracked files
smartgit utils suggest-gitignore
# Safe force push (force-with-lease)
smartgit utils force-push-safe
# Create fixup commit
smartgit utils fixup <commit-hash>
# Get help for any utility
smartgit utils --help
Configuration
# View current configuration
smartgit config show
# Set configuration values
smartgit config set provider anthropic
smartgit config set model claude-3-5-sonnet-20241022
smartgit config set commit_style conventional
# Set global configuration (applies to all repos)
smartgit config set provider anthropic --global
# Reset configuration to defaults
smartgit config reset
Configuration Files
smartgit supports hierarchical configuration:
- Repository Config (highest priority):
.smartgit.ymlin your repo root - User Config:
~/.config/smartgit/config.yml - Environment Variables:
.envfile or shell exports
Example Configuration
Create a .smartgit.yml file in your repository:
# AI Provider Configuration
provider: anthropic # or openai
model: claude-3-5-sonnet-20241022
# Commit Message Settings
commit_style: conventional # or simple
max_subject_length: 72
context_lines: 3
# Behavior Settings
auto_add: false
hook_enabled: true
max_diff_size: 10000
Environment Variables
# Required
ANTHROPIC_API_KEY=your_anthropic_api_key
# Optional
OPENAI_API_KEY=your_openai_key # if using OpenAI provider
SMARTGIT_PROVIDER=anthropic
SMARTGIT_MODEL=claude-3-5-sonnet-20241022
SMARTGIT_COMMIT_STYLE=conventional
Commit Message Format
smartgit generates commit messages following the Conventional Commits specification:
<type>(<scope>): <subject>
<body>
<footer>
Commit Types
| Type | Description | Example |
|---|---|---|
feat |
New feature | feat(auth): add JWT authentication |
fix |
Bug fix | fix(api): handle null response from endpoint |
docs |
Documentation changes | docs(readme): add installation instructions |
style |
Code style changes | style(components): format with prettier |
refactor |
Code refactoring | refactor(db): optimize query performance |
perf |
Performance improvements | perf(api): cache frequent database queries |
test |
Adding or updating tests | test(auth): add unit tests for login flow |
build |
Build system changes | build(deps): upgrade to webpack 5 |
ci |
CI configuration changes | ci(github): add automated release workflow |
chore |
Maintenance tasks | chore(deps): update dependencies |
Examples
Example 1: Feature Addition
$ git add src/auth.py
$ smartgit generate
✨ Analyzing staged changes...
Generated Commit Message:
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ feat(auth): add JWT token authentication ┃
┃ ┃
┃ Implement JWT-based authentication system with ┃
┃ token generation and validation. ┃
┃ ┃
┃ - Add token generation utility ┃
┃ - Add token validation middleware ┃
┃ - Add refresh token support ┃
┃ - Configure token expiration settings ┃
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
Create commit with this message? (y/n): y
✓ Commit created successfully!
Example 2: Using Utilities
$ smartgit utils stale --days 30
🔍 Finding stale branches...
Branches not updated in 30 days:
┏━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┳━━━━━━━━━━━┓
┃ Branch ┃ Last Updated ┃ Days Ago ┃
┡━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━╇━━━━━━━━━━━┩
│ feature/old-api │ 2024-11-15 │ 45 │
│ bugfix/temp-fix │ 2024-11-20 │ 40 │
│ experiment/new-design │ 2024-10-10 │ 80 │
└───────────────────────┴───────────────┴───────────┘
💡 Tip: Use 'git branch -D <branch>' to delete local branches
Example 3: Status Check
$ smartgit status
📊 Git AI Status Report
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Repository: smartgit
Branch: main
Status: Clean ✓
Git Hooks:
✓ prepare-commit-msg installed
Location: .git/hooks/prepare-commit-msg
AI Configuration:
Provider: anthropic
Model: claude-3-5-sonnet-20241022
Commit Style: conventional
API Key: ✓ Found
Requirements
- Python: 3.8 or higher
- Git: 2.0 or higher
- API Key: Anthropic API key (or OpenAI if using that provider)
Development
Setup Development Environment
# Clone the repository
git clone https://github.com/SifatIbna/smart-git-ai.git
cd smart-git-ai
# Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install in development mode with dev dependencies
pip install -e ".[dev]"
Run Tests
# Run all tests
pytest
# Run with coverage
pytest --cov=smartgit --cov-report=html --cov-report=term-missing
# Run specific test file
pytest tests/unit/test_repository.py
Code Quality
# Format code
python -m ruff format src tests
# Lint code
python -m ruff check src tests
# Type check
python -m mypy src
# Run all checks (what CI runs)
python -m ruff check --fix src tests && \
python -m ruff format src tests && \
python -m mypy src && \
pytest --cov=smartgit
Pre-commit Hooks
# Install pre-commit hooks
pre-commit install
# Run manually
pre-commit run --all-files
Documentation
- QUICKSTART.md - Detailed getting started guide
- CONTRIBUTING.md - Contribution guidelines
- RELEASING.md - Release process
Contributing
We welcome contributions! Here's how you can help:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Make your changes
- Run tests and linting (
pytest && ruff check .) - Commit your changes (use
smartgit generate😉) - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Please read CONTRIBUTING.md for detailed guidelines.
Development Philosophy
- Quality over Speed: We prioritize well-tested, maintainable code
- User First: Features should solve real problems for real developers
- Keep It Simple: Prefer simple solutions over complex abstractions
- Document Everything: Code should be self-documenting, but docs help
Troubleshooting
"Not a git repository" error
Make sure you're inside a git repository:
git init # Initialize a new repository if needed
"API key not found" error
Ensure your API key is properly set:
# Check if it's set
echo $ANTHROPIC_API_KEY
# Set it if missing
export ANTHROPIC_API_KEY="your_key_here"
# Or add to .env file
echo "ANTHROPIC_API_KEY=your_key_here" > .env
Hook not working
Reinstall hooks with force flag:
smartgit uninstall
smartgit install --force
"Large diff" warning
If your changes are too large:
# Commit in smaller chunks
git add specific-file.py
smartgit generate
# Or increase the limit
smartgit config set max_diff_size 20000
Getting Help
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- Email: sifatibna@gmail.com
Roadmap
- Support for more AI providers (Google Gemini, local models)
- Interactive mode for commit message editing
- Commit message templates and customization
- Integration with GitHub CLI for PR descriptions
- VS Code extension
- Commit message translation to different languages
- Team collaboration features (shared configs, style guides)
License
MIT License - see LICENSE for details.
Acknowledgments
- Powered by Anthropic's Claude - State-of-the-art AI for understanding code
- Inspired by Conventional Commits - A specification for meaningful commit messages
- Built with:
- Click - Beautiful command line interfaces
- Rich - Rich text and formatting in terminal
- GitPython - Git interface library
- Anthropic SDK - Official Anthropic API client
Made with ❤️ by Master Shifu, for developers
If you find this project helpful, please consider giving it a ⭐️ on GitHub!
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
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 smart_git_ai-0.1.4.tar.gz.
File metadata
- Download URL: smart_git_ai-0.1.4.tar.gz
- Upload date:
- Size: 26.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e71e479030dee38683ccb6a290d9ec383d248eb1a496e6b8f3dda530d12cdf80
|
|
| MD5 |
a1afa2dbe6a16fdd38517f314a65e871
|
|
| BLAKE2b-256 |
4013bb3e117e4842585326bdd6742aa17b40df4aff129bc15002bd4aa3ba328e
|
File details
Details for the file smart_git_ai-0.1.4-py3-none-any.whl.
File metadata
- Download URL: smart_git_ai-0.1.4-py3-none-any.whl
- Upload date:
- Size: 31.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0a00c000e6e9c19552e7b65bedbcb5557eae9b309c8768798183824cde3321f7
|
|
| MD5 |
de95aab62dbb0b838102f4f967bf44cd
|
|
| BLAKE2b-256 |
534743685cd9b21f4668d3fdde54372e110099bab8366b2d89fa0b5a76ddada3
|