Skip to main content

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 commit if 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:

  1. Analyze your staged changes.
  2. Generate a commit message using the Gemini API.
  3. Warn if the message doesn't follow Conventional Commits.
  4. 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

  1. Stage some changes:

    git add .
    
  2. Run the tool:

    git-commit-gen
    
  3. 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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

git_commit_gen-0.1.1.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

git_commit_gen-0.1.1-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

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

Hashes for git_commit_gen-0.1.1.tar.gz
Algorithm Hash digest
SHA256 13bb11fb9ae61cd3ec74ba4c20f8260d6a0cf683f813b639cb9c57d0e30b0727
MD5 2542dae5d94157f60794467c629059d6
BLAKE2b-256 e27af1a501639931ecc3b138d785566aa09916b12a1887573a1cf69d1895a381

See more details on using hashes here.

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

Hashes for git_commit_gen-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 dce0dff4f7fed8ed0276f09e53f5e6dd6a536949c9cf698cc881fa209c38b8e3
MD5 4cb994e7a751d62cd9d7c50d270f69bc
BLAKE2b-256 663c9c895a4b9e792f05b19eed8f28a6747dfd60fbd20a12a576e44d047483f6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page