Skip to main content

A tool to generate conventional commit messages using Gemini API

Project description

Git Commit Gen

PyPI version Build Status

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.2.tar.gz (4.8 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.2-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

Details for the file git_commit_gen-0.1.2.tar.gz.

File metadata

  • Download URL: git_commit_gen-0.1.2.tar.gz
  • Upload date:
  • Size: 4.8 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.2.tar.gz
Algorithm Hash digest
SHA256 33dec0770bd1a5f05dbe481cba530cafa348af52c8e0c1eaeb577480a584698e
MD5 7260eb1f795baef1a2f1e4765ee468e4
BLAKE2b-256 6076d6607c2873c81c94355624b262aab64450a61e958cb74d09cc3eb007f838

See more details on using hashes here.

File details

Details for the file git_commit_gen-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: git_commit_gen-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 6.2 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 f9c0e536a830ce5e0cd8b1956e37caf52c5c303d8cdd9285341cdd70962e5cb7
MD5 9bcbda1976e4a50847d2f1c2eb5f24be
BLAKE2b-256 0208c0d45abb6b6ef44665dc6dd1ef45856d09c146293cadab0e2030d091448c

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