An AI-powered git commit message generator.
Project description
gai-commit
AI-powered CLI tool to generate commit messages from your staged Git changes. Works with both local Ollama models and OpenAI's API.
Installation
pip install gai-commit
Usage Options
1. Using Ollama (Local LLMs)
Ollama provides free, locally-running AI models with no API keys required.
Prerequisites:
# 1. Install Ollama (https://ollama.com)
# 2. Pull a model (only needed once):
ollama pull llama3.2
# Ollama daemon should start automatically after installation
Basic Usage:
# Stage your changes first
git add path/to/modified/files
# Generate commit message with default model
gai
# Or specify a different Ollama model
gai deepseek-r1:8b
2. Using OpenAI (Cloud-based LLMs)
For higher quality results, you can use OpenAI's models (requires API key).
Prerequisites:
# Set your OpenAI API key (or add to .env file)
export OPENAI_API_KEY=sk-your-key
Basic Usage:
# Stage your changes first
git add path/to/modified/files
# Generate commit message with default model (gpt-3.5-turbo)
gai --provider openai
# Or specify a different OpenAI model
gai --provider openai gpt-4o
Additional Options
# Generate a concise one-line commit message (subject only)
gai --oneline
# Combine with provider selection
gai --provider openai --oneline
How It Works
- Repository Check: Verifies you're in a git repository via
gai.utils.is_git_repository - Diff Collection: Gets staged changes with
git diff --staged --minimal --unified=5usinggai.utils.get_staged_diff - AI Processing: Sends the cleaned diff to the selected AI provider through
gai.cli.generate_commit_message - Output Cleaning: Formats the AI output and removes technical artifacts via
gai.utils.clean_commit_message - Interactive Workflow: Presents options to apply, edit, regenerate or quit via
gai.cli.handle_user_choice - Commit: Applies your approved message with
git commit
Interactive Workflow
After generating a commit message suggestion, you'll see:
Suggested Commit Message:
feat(parser): improve error resilience
- add fallback recovery for malformed input
- reduce panic cases in edge parsing paths
---
[A]pply, [E]dit, [R]-generate, or [Q]uit? (a/e/r/q)
Your options:
- A: Apply immediately (
git commit -m "<message>") - E: Open your
$EDITOR(defaults tovim) to refine the message - R: Ask the AI to generate a new suggestion using the same diff
- Q: Quit without committing
Troubleshooting
Common Issues
- "No staged changes found": Use
git addto stage your changes first - "Not a Git repository": Make sure you're inside a valid git repository
- "OPENAI_API_KEY environment variable not set": Set your OpenAI API key or use Ollama
- "Ollama connection refused": Make sure the Ollama daemon is running (
ollama serve)
Development
# Clone the repository
git clone https://github.com/muzahid59/gai
cd gai
# Install in development mode
pip install -e .
# Run tests
pytest tests -v
Benchmarking
Compare different models' performance:
# Make sure to stage some changes first
python run_benchmark.py
License
MIT - see LICENSE
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 gai_commit-0.1.2.tar.gz.
File metadata
- Download URL: gai_commit-0.1.2.tar.gz
- Upload date:
- Size: 14.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
24cbae30255e85db6984f6eb27c646886a2e9deec5eabf948f566d21be72233a
|
|
| MD5 |
2113f6f646f88432b85f7b896eca6c4f
|
|
| BLAKE2b-256 |
37f887ba52afd0c99f50dd9a5ceb808b54ebb1a6123e70eb8d98556367af09f6
|
Provenance
The following attestation bundles were made for gai_commit-0.1.2.tar.gz:
Publisher:
publish.yml on muzahid59/gai
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
gai_commit-0.1.2.tar.gz -
Subject digest:
24cbae30255e85db6984f6eb27c646886a2e9deec5eabf948f566d21be72233a - Sigstore transparency entry: 397020531
- Sigstore integration time:
-
Permalink:
muzahid59/gai@c3ab8dea26ab529e6451c4407fda61ca17b250c4 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/muzahid59
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@c3ab8dea26ab529e6451c4407fda61ca17b250c4 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file gai_commit-0.1.2-py3-none-any.whl.
File metadata
- Download URL: gai_commit-0.1.2-py3-none-any.whl
- Upload date:
- Size: 12.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a1512e48f96802aca698647239eff5c837a8886736b7853705ead95a16b9c12f
|
|
| MD5 |
f1e697f1aab5635860733b0ea482d911
|
|
| BLAKE2b-256 |
206c3eec04249d295f8ffc94cf8abcf6d9d334889b92d5de13397da42e721b73
|
Provenance
The following attestation bundles were made for gai_commit-0.1.2-py3-none-any.whl:
Publisher:
publish.yml on muzahid59/gai
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
gai_commit-0.1.2-py3-none-any.whl -
Subject digest:
a1512e48f96802aca698647239eff5c837a8886736b7853705ead95a16b9c12f - Sigstore transparency entry: 397020551
- Sigstore integration time:
-
Permalink:
muzahid59/gai@c3ab8dea26ab529e6451c4407fda61ca17b250c4 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/muzahid59
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@c3ab8dea26ab529e6451c4407fda61ca17b250c4 -
Trigger Event:
workflow_dispatch
-
Statement type: