Generate meaningful git commit messages from your staged diff using OpenAI GPT. Supports interactive edit, dry-run mode, and CI pipelines.
pip install openai
curl -o /usr/local/bin/ai-commit https://raw.githubusercontent.com/breitzer/ai-commit/main/ai_commit.py
chmod +x /usr/local/bin/ai-commitOr clone:
git clone https://github.com/breitzer/ai-commit.git
cd ai-commit && bash install.shexport OPENAI_API_KEY=sk-...
# Add to ~/.bashrc or ~/.zshrc to persist# Stage your changes first, then:
ai-commit
# Stage all tracked changes automatically
ai-commit --all
# Print message without committing
ai-commit --dry-run
# Add context (ticket number, PR description)
ai-commit --context "closes #42, refactors auth middleware"
# Use a specific model
ai-commit --model gpt-4o$ git add app/Http/Middleware/AuthMiddleware.php
$ ai-commit
Generating commit message with gpt-4.1-mini...
────────────────────────────────────────────────────────────
Proposed commit message:
refactor(auth): extract token validation into AuthMiddleware
- Moves JWT decode logic out of controllers for single responsibility
- Adds early return on missing Authorization header
- Fixes edge case where expired tokens returned 500 instead of 401
────────────────────────────────────────────────────────────
[c]ommit / [e]dit / [a]bort? c
[main a3f91c2] refactor(auth): extract token validation into AuthMiddleware
Committed.
| Flag | Description |
|---|---|
--all, -a |
Run git add -u before generating |
--dry-run, -n |
Print message without committing |
--context, -c |
Extra hint for the model |
--model, -m |
OpenAI model (default: gpt-4.1-mini) |
--no-verify |
Skip pre-commit hooks |
- Python 3.8+
openaipackageOPENAI_API_KEYenvironment variable
MIT