A command-line tool to automatically generate concise and informative commit messages following the Conventional Commits specification using the Google Gemini API.
- Analyzes staged Git changes (modified, added, and deleted files).
- Generates commit messages based on file diffs and changes.
- Ensures messages adhere to Conventional Commits format (e.g.,
feat: add new feature). - Falls back to standard
git commitif generation fails.
Install the package via pip:
pip install git-commit-gen- Python 3.8 or higher
- Git installed and configured
- A Google Gemini API key (see Configuration)
Run the tool in a Git repository with staged changes:
git-commit-genYou can pass additional Git commit options:
git-commit-gen --amend
git-commit-gen -vThe tool will:
- Analyze your staged changes.
- Generate a commit message using the Gemini API.
- Warn if the message doesn't follow Conventional Commits.
- Execute the commit with the generated message.
The tool requires a Google Gemini API key. Set it in a .env file in your working directory or as an environment variable:
Create a .env file in your project root:
GEMINI_API_KEY=your_api_key_here
Set the key in your shell:
export GEMINI_API_KEY=your_api_key_hereOptional environment variables:
GEMINI_MODEL: Specify the Gemini model (default:gemini-2.0-flash-001).MAX_DIFF_SIZE: Maximum diff size to include in the prompt (default:2000).
-
Stage some changes:
git add . -
Run the tool:
git-commit-gen
-
Output might look like:
feat: implement user authentication
If the generated message doesn't follow Conventional Commits:
Warning: Generated commit message may not follow Conventional Commits.
It is recommended to review and adjust the message before committing.
Proposed message: update readme file
git_commit_gen/
├── git_commit_gen/
│ ├── __init__.py
│ └── git_commit_gen.py
├── pyproject.toml
└── README.md
To build locally:
pip install hatchling build
python -m buildpip install dist/git_commit_gen-0.1.0-py3-none-any.whlFeel free to submit issues or pull requests on the GitHub repository
This project is licensed under the MIT License - see the LICENSE file for details.
- Built with Google Gemini API.