Skip to main content

Generate Conventional Commit messages from your staged changes using an LLM

Project description

git-llm-commit

codecov

Generate Conventional Commit messages from your staged changes using an LLM.

Description

git-llm-commit is a command-line tool that analyzes your staged git changes and generates a commit message following the Conventional Commits specification using various LLM models, including OpenAI's GPT-4 and OpenRouter.

Installation

  1. Ensure you have Python 3.x installed
  2. Install the package:
    pip install git-llm-commit
    

Setup

  1. Get an API key from your preferred LLM provider (e.g., OpenAI, OpenRouter)

  2. Set your API key in your environment:

    export OPENAI_API_KEY='your-api-key'
    

    Or create a .env file in your project root with:

    OPENAI_API_KEY=your-api-key
    
  3. (Optional) Customize the LLM's creativity:

    export LLM_COMMIT_TEMPERATURE='0.5'  # More deterministic (0.0-1.0, default: 0.7)
    

    Or in your .env file:

    LLM_COMMIT_TEMPERATURE=0.5
    
  4. (Optional) Use OpenRouter:

    • Get an OpenRouter API key from OpenRouter's platform

    • Set your OpenRouter API key in your environment:

      export OPENROUTER_API_KEY='your-openrouter-api-key'
      

      Or in your .env file:

      OPENROUTER_API_KEY=your-openrouter-api-key
      
  5. (Optional) Choose a custom model:

    • Set the model name in your environment:

      export LLM_COMMIT_MODEL='custom-model'
      

      Or in your .env file:

      LLM_COMMIT_MODEL=custom-model
      

Usage

  1. Stage your changes as usual:

    git add .
    
  2. Instead of git commit, run:

    git llm-commit
    
  3. Review the generated commit message and:

    • Press y to accept and commit
    • Press n to abort
    • Press e to edit the message before committing

Features

  • Generates commit messages following Conventional Commits format
  • Uses various LLM models to analyze diffs and create meaningful commit messages
  • Adapts commit message detail based on change size:
    • Small changes (≤50 lines): Concise, single-line messages
    • Medium changes (51-200 lines): Moderate detail with brief body
    • Large changes (>200 lines): Detailed messages with full body and footers
  • Supports interactive editing of generated messages
  • Integrates with your default git editor
  • Respects conventional commit types: feat, fix, docs, style, refactor, perf, test, build, ci, chore, revert
  • Detects potentially risky files (like .env, credentials, secrets) and prompts for confirmation before committing
  • Prioritizes OpenRouter API key if available, otherwise falls back to OpenAI API key
  • Allows users to choose the model they would like to use

Security Features

Risky File Detection

The tool automatically scans staged files for potentially sensitive content like:

  • .env files
  • Files containing "secret" or "credentials" in the name
  • Key files
  • Secret/credential configuration files (yml, yaml, json, toml)

If such files are detected, you'll be prompted for confirmation before proceeding with the commit. This helps prevent accidental commits of sensitive information to your repository.

Requirements

  • Python 3.x
  • Git
  • API key from your preferred LLM provider (e.g., OpenAI, OpenRouter)

License

MIT License

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_llm_commit-2.0.0.tar.gz (42.6 kB view details)

Uploaded Source

Built Distribution

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

git_llm_commit-2.0.0-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

Details for the file git_llm_commit-2.0.0.tar.gz.

File metadata

  • Download URL: git_llm_commit-2.0.0.tar.gz
  • Upload date:
  • Size: 42.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.29

File hashes

Hashes for git_llm_commit-2.0.0.tar.gz
Algorithm Hash digest
SHA256 75ee034b8c2c5652913297caaf29fd1776da709627913406f9dd557ea560dadb
MD5 b33b56c34e85843ff9e4091c4c3e8f1b
BLAKE2b-256 d2b8e59847e3609d0952e1427c38052eabe61ad5f714adcc514052e09df25512

See more details on using hashes here.

File details

Details for the file git_llm_commit-2.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for git_llm_commit-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3c54a540874250f3c6f4b011723a8bcb1e2c10997e2e3d43dcba199e55d1fc1e
MD5 2a3957dc70f20596ba70647bd76453cd
BLAKE2b-256 7ac0504bcc03e7b7996e7036768740d714784e9701133b4f1c6f3a39a2c2d6e0

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