| .github/workflows | ||
| scripts | ||
| src/git_llm_commit | ||
| tests | ||
| .clinerules | ||
| .cz.toml | ||
| .gitignore | ||
| .python-version | ||
| CHANGELOG.md | ||
| LICENSE | ||
| pyproject.toml | ||
| README.md | ||
| uv.lock | ||
git-llm-commit
Generate Conventional Commit messages from your staged changes using an LLM.
Description
git-llm-commit is a command-line tool that analyzes your staged git changes and generates a commit message following the Conventional Commits specification using various LLM models, including OpenAI's GPT-4 and OpenRouter.
Installation
- Ensure you have Python 3.x installed
- Install the package:
pip install git-llm-commit
Setup
-
Get an API key from your preferred LLM provider (e.g., OpenAI, OpenRouter)
-
Set your API key in your environment:
export OPENAI_API_KEY='your-api-key'Or create a
.envfile in your project root with:OPENAI_API_KEY=your-api-key -
(Optional) Customize the LLM's creativity:
export LLM_COMMIT_TEMPERATURE='0.5' # More deterministic (0.0-1.0, default: 0.7)Or in your
.envfile:LLM_COMMIT_TEMPERATURE=0.5 -
(Optional) Use OpenRouter:
-
Get an OpenRouter API key from OpenRouter's platform
-
Set your OpenRouter API key in your environment:
export OPENROUTER_API_KEY='your-openrouter-api-key'Or in your
.envfile:OPENROUTER_API_KEY=your-openrouter-api-key
-
-
(Optional) Choose a custom model:
-
Set the model name in your environment:
export LLM_COMMIT_MODEL='custom-model'Or in your
.envfile:LLM_COMMIT_MODEL=custom-model
-
Usage
-
Stage your changes as usual:
git add . -
Instead of
git commit, run:git llm-commit -
Review the generated commit message and:
- Press
yto accept and commit - Press
nto abort - Press
eto edit the message before committing
- Press
-
For detailed commit messages with body and footer sections:
git llm-commit --dynamicor set the environment variable:
export LLM_COMMIT_DYNAMIC_LENGTH=true
Features
- Generates commit messages following Conventional Commits format
- By default, generates one-sentence commit messages (title only) for simplicity
- Optional dynamic mode (--dynamic flag) that adapts commit message detail based on change size:
- Small changes (≤50 lines): Concise, single-line messages
- Medium changes (51-200 lines): Moderate detail with brief body
- Large changes (>200 lines): Detailed messages with full body and footers
- Supports interactive editing of generated messages
- Integrates with your default git editor
- Respects conventional commit types: feat, fix, docs, style, refactor, perf, test, build, ci, chore, revert
- Detects potentially risky files (like .env, credentials, secrets) and prompts for confirmation before committing
- Prioritizes OpenRouter API key if available, otherwise falls back to OpenAI API key
- Allows users to choose the model they would like to use
Security Features
Risky File Detection
The tool automatically scans staged files for potentially sensitive content like:
.envfiles- Files containing "secret" or "credentials" in the name
- Key files
- Secret/credential configuration files (yml, yaml, json, toml)
If such files are detected, you'll be prompted for confirmation before proceeding with the commit. This helps prevent accidental commits of sensitive information to your repository.
Requirements
- Python 3.x
- Git
- API key from your preferred LLM provider (e.g., OpenAI, OpenRouter)