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.0.tar.gz (4.4 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.0-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: git_commit_gen-0.1.0.tar.gz
  • Upload date:
  • Size: 4.4 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.0.tar.gz
Algorithm Hash digest
SHA256 a7b6e2a5de46b8a03fefd7b5fe5c1bd6a6fc7649f10362f757296a541ed916f3
MD5 4254d32ae55bfd153d5e49e12a4a9188
BLAKE2b-256 1defa2cfd68c380f003e56fbd29e642e922470a40aa56ebbec50db4d41fed886

See more details on using hashes here.

File details

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

File metadata

  • Download URL: git_commit_gen-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.8 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 53daac6ca1c5d767c7f0dfe1f360a0a9defced6b369b2b91249c41037b9af308
MD5 135d151610c29f195911f4ebe88bf1fe
BLAKE2b-256 23c1c703c5dab6b3d1e1080d19a089c32f5dcde559657f8a47e14c59a7596bb4

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