Generate meaningful Git commit messages automatically using the Flan-T5 language model. Works completely offline and is CPU-friendly!
- 🤖 AI-Powered : Uses Google's Flan-T5 model to understand code changes
- 💻 CPU-Friendly : No GPU required, runs on any machine
- 🔒 Offline : Works without internet connection after initial model download
- 📝 Conventional Commits : Supports standard commit types (feat, fix, docs, etc.)
- ⚡ Fast : Generates messages in seconds
- 🎯 Smart : Analyzes actual code changes, not just file names
- Python 3.8 or higher
- Git installed on your system
- Clone or download the project :
cd ai-commit-gen- Create a virtual environment (recommended):
python -m venv venv
# On Windows
venv\Scripts\activate
# On macOS/Linux
source venv/bin/activate- Install dependencies :
pip install -r requirements.txt- First run (downloads the model):
python commitgen.py --helpThe first time you run the tool, it will download the Flan-T5 model (~240 MB). This is a one-time download.
- Stage your changes :
git add .- Generate a commit message :
python commitgen.pySpecify commit type :
python commitgen.py --type feat
python commitgen.py --type fix
python commitgen.py --type docsAdd a scope :
python commitgen.py --type feat --scope auth
# Output: feat(auth): added password validation and strength checkerShow the diff being analyzed :
python commitgen.py --show-diffAuto-commit with generated message :
python commitgen.py --auto-commitCustom message length :
python commitgen.py --max-length 50Use a different model :
# Default is flan-t5-small (~240MB)
python commitgen.py --model google/flan-t5-base # ~900MB, better quality# After adding a new login feature
git add src/auth/login.py
python commitgen.py --type feat --scope auth
# Output: feat(auth): implemented user login with email validation# After fixing a bug
git add src/api/users.py
python commitgen.py --type fix
# Output: fix: resolved null pointer exception in user data retrieval# After updating README
git add README.md
python commitgen.py --type docs
# Output: docs: updated installation instructions and added examplesFollowing Conventional Commits specification:
feat: A new featurefix: A bug fixdocs: Documentation changesstyle: Code style changes (formatting, missing semi-colons, etc.)refactor: Code refactoringtest: Adding or updating testschore: Maintenance tasks
- Stage related changes together : The AI works best when analyzing cohesive changes
- Use specific file staging :
git add specific-file.pyfor focused messages - Review before committing : Always review the generated message
- Combine with scope : Use
--scopeto add context (e.g.,--scope api)
ai-commit-gen/
├── commitgen.py # Main CLI application
├── utils.py # Helper functions and model logic
├── requirements.txt # Python dependencies
├── README.md # This file
└── examples/
└── sample_diff.txt # Example diff for testing
- Extracts Git diff : Reads your staged changes using
git diff --cached - Prepares input : Cleans and formats the diff for the AI model
- AI analysis : Flan-T5 analyzes the changes and generates a summary
- Formats output : Applies conventional commit formatting
- Returns message : Displays the generated commit message
The tool supports different Flan-T5 variants:
| Model | Size | Quality | Speed |
|---|---|---|---|
| flan-t5-small | 240 MB | Good | Fast |
| flan-t5-base | 900 MB | Better | Medium |
| flan-t5-large | 3 GB | Best | Slow |
Default is flan-t5-small for the best balance of size and performance.
You can set default options via environment variables:
export COMMITGEN_MODEL="google/flan-t5-base"
export COMMITGEN_MAX_LENGTH="50"Make sure you're running the tool from within a Git repository.
Stage your changes first with git add <files>.
Check your internet connection. The model needs to be downloaded once.
Try using a smaller model:
python commitgen.py --model google/flan-t5-small- VS Code extension
- Git hook integration (pre-commit)
- GitHub Action
- Custom prompt templates
- Multi-language support
- Commit history analysis
- Support for more LLMs (TinyLlama, etc.)
MIT License - Feel free to use and modify!
Contributions are welcome! Feel free to:
- Report bugs
- Suggest features
- Submit pull requests
Made with ❤️ for developers who care about good commit messages