GitHub - nurv/gencommit: Autogenerate git commit message.

2 min read Original article ↗

git-gencommit

AI-powered git commit message generator using OpenAI. Generate high-quality commit messages from your staged changes with a single command.

Features

  • Generates commit messages from staged git diffs using OpenAI
  • Multiple commit message formats: detailed (default), conventional commits, or simple
  • Configurable OpenAI model (defaults to gpt-4o)
  • Interactive editing flow: accept, reject, or edit generated messages
  • Uses OpenAI structured outputs for reliable formatting
  • Validates OPENAI_API_KEY before running

Installation

Prerequisites

  • Python 3.8 or higher
  • Git
  • OpenAI API key

Setup

  1. Clone or download this repository:
cd /Users/nurv/git/gencommit
  1. Install the package:

This will install the git-gencommit command globally, making it available as git gencommit.

  1. Set your OpenAI API key:
export OPENAI_API_KEY='your-api-key-here'

Add this to your ~/.bashrc, ~/.zshrc, or equivalent to make it permanent.

Usage

Basic Usage

  1. Stage your changes:
  1. Generate and commit:

The tool will:

  • Analyze your staged changes
  • Generate a commit message using AI
  • Show you the message and prompt for acceptance
  • Allow you to accept (a), edit (e), or reject (r) the message
  • Commit with the final message

Command Line Options

Options:

  • --model <model>: Specify OpenAI model to use (default: gpt-4o)

    • Examples: gpt-4o, gpt-4o-mini, gpt-3.5-turbo
  • --format <format>: Choose commit message format (default: detailed)

    • detailed: Multi-line message with summary and detailed body
    • conventional: Conventional Commits format (type(scope): description)
    • simple: Single-line descriptive message

Examples

Using a different model:

git gencommit --model gpt-4o-mini

Using conventional commits format:

git gencommit --format conventional

Using simple format with different model:

git gencommit --format simple --model gpt-3.5-turbo

Interactive Editing

When the commit message is displayed, you'll be prompted:

Accept (a), Edit (e), or Reject (r)? [a/e/r]:
  • a (Accept): Use the generated message as-is
  • e (Edit): Enter a new message interactively (end with a line containing just .)
  • r (Reject): Cancel the commit

Error Handling

The tool will display helpful error messages if:

  • OPENAI_API_KEY is not set
  • No changes are staged
  • Git is not installed
  • API calls fail

Commit Message Formats

Detailed (Default)

Add user authentication system

Implements JWT-based authentication with login and registration
endpoints. Includes password hashing with bcrypt and token
validation middleware.

Conventional Commits

feat(auth): add user authentication system

Implements JWT-based authentication with login and registration
endpoints. Includes password hashing and token validation.

Simple

Add user authentication with JWT and bcrypt

Uninstallation

pip uninstall git-gencommit

License

MIT

Contributing

Contributions are welcome! Please feel free to submit issues or pull requests.