A tool to generate conventional commit messages using Gemini API
Project description
Git Commit Gen
A command-line tool to automatically generate concise and informative commit messages following the Conventional Commits specification using the Google Gemini API.
Features
- 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.
Installation
Install the package via pip:
pip install git-commit-gen
Prerequisites
- Python 3.8 or higher
- Git installed and configured
- A Google Gemini API key (see Configuration)
Usage
Run the tool in a Git repository with staged changes:
git-commit-gen
You can pass additional Git commit options:
git-commit-gen --amend
git-commit-gen -v
The 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.
Configuration
The tool requires a Google Gemini API key. Set it in a .env file in your working directory or as an environment variable:
Using a .env file
Create a .env file in your project root:
GEMINI_API_KEY=your_api_key_here
Using environment variables
Set the key in your shell:
export GEMINI_API_KEY=your_api_key_here
Optional 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).
Example
-
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
Development
Project Structure
git_commit_gen/
├── git_commit_gen/
│ ├── __init__.py
│ └── git_commit_gen.py
├── pyproject.toml
└── README.md
Build the Package
To build locally:
pip install hatchling build
python -m build
Install Locally
pip install dist/git_commit_gen-0.1.0-py3-none-any.whl
Contributing
Feel free to submit issues or pull requests on the GitHub repository
License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgments
- Built with Google Gemini API.
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 git_commit_gen-0.1.1.tar.gz.
File metadata
- Download URL: git_commit_gen-0.1.1.tar.gz
- Upload date:
- Size: 4.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
13bb11fb9ae61cd3ec74ba4c20f8260d6a0cf683f813b639cb9c57d0e30b0727
|
|
| MD5 |
2542dae5d94157f60794467c629059d6
|
|
| BLAKE2b-256 |
e27af1a501639931ecc3b138d785566aa09916b12a1887573a1cf69d1895a381
|
File details
Details for the file git_commit_gen-0.1.1-py3-none-any.whl.
File metadata
- Download URL: git_commit_gen-0.1.1-py3-none-any.whl
- Upload date:
- Size: 6.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dce0dff4f7fed8ed0276f09e53f5e6dd6a536949c9cf698cc881fa209c38b8e3
|
|
| MD5 |
4cb994e7a751d62cd9d7c50d270f69bc
|
|
| BLAKE2b-256 |
663c9c895a4b9e792f05b19eed8f28a6747dfd60fbd20a12a576e44d047483f6
|