Skip to main content

Generate Git commit messages from staged changes using LLM

Project description

git-commit-message

Generate a commit message from your staged changes using OpenAI, Google Gemini, or Ollama.

asciicast

Requirements

  • Python 3.13+
  • A Git repo with staged changes (git add ...)

Install

Install the latest released version from PyPI:

# User environment (recommended)
python -m pip install --user git-commit-message

# Or system/virtualenv as appropriate
python -m pip install git-commit-message

# Or with pipx for isolated CLI installs
pipx install git-commit-message

# Upgrade to the newest version
python -m pip install --upgrade git-commit-message

Quick check:

git-commit-message --help

Setup

OpenAI

export OPENAI_API_KEY="sk-..."

Google Gemini

export GOOGLE_API_KEY="..."

Ollama (local models)

  1. Install Ollama: https://ollama.ai
  2. Start the server:
ollama serve
  1. Pull a model:
ollama pull mistral

Optional: set defaults:

export GIT_COMMIT_MESSAGE_PROVIDER=ollama
export OLLAMA_MODEL=mistral

Note (fish):

set -x OPENAI_API_KEY "sk-..."

Install (editable)

python -m pip install -e .

Usage

Generate and print a commit message:

git add -A
git-commit-message "optional extra context about the change"

Generate a single-line subject only:

git-commit-message --one-line "optional context"

Select provider:

# OpenAI (default)
git-commit-message --provider openai

# Google Gemini (via google-genai)
git-commit-message --provider google

# Ollama
git-commit-message --provider ollama

Commit immediately (optionally open editor):

git-commit-message --commit "refactor parser for speed"
git-commit-message --commit --edit "refactor parser for speed"

Limit subject length:

git-commit-message --one-line --max-length 50

Chunk/summarise long diffs by token budget:

# force a single summary pass over the whole diff (default)
git-commit-message --chunk-tokens 0

# chunk the diff into ~4000-token pieces before summarising
git-commit-message --chunk-tokens 4000

# disable summarisation and use the legacy one-shot prompt
git-commit-message --chunk-tokens -1

Select output language/locale (IETF language tag):

git-commit-message --language en-US
git-commit-message --language ko-KR
git-commit-message --language ja-JP

Print debug info:

git-commit-message --debug

Configure Ollama host (if running on a different machine):

git-commit-message --provider ollama --host http://192.168.1.100:11434

Options

  • --provider {openai,google,ollama}: provider to use (default: openai)
  • --model MODEL: model override (provider-specific)
  • --language TAG: output language/locale (default: en-GB)
  • --one-line: output subject only
  • --max-length N: max subject length (default: 72)
  • --chunk-tokens N: token budget per diff chunk (0 = single summary pass, -1 disables summarisation)
  • --debug: print request/response details
  • --commit: run git commit -m <message>
  • --edit: with --commit, open editor for final message
  • --host URL: host URL for providers like Ollama (default: http://localhost:11434)

Environment variables

Required:

  • OPENAI_API_KEY: when provider is openai
  • GOOGLE_API_KEY: when provider is google

Optional:

  • GIT_COMMIT_MESSAGE_PROVIDER: default provider (openai by default). --provider overrides this.
  • GIT_COMMIT_MESSAGE_MODEL: model override for any provider. --model overrides this.
  • OPENAI_MODEL: OpenAI-only model override (used if --model/GIT_COMMIT_MESSAGE_MODEL are not set)
  • OLLAMA_MODEL: Ollama-only model override (used if --model/GIT_COMMIT_MESSAGE_MODEL are not set)
  • OLLAMA_HOST: Ollama server URL (default: http://localhost:11434)
  • GIT_COMMIT_MESSAGE_LANGUAGE: default language/locale (default: en-GB)
  • GIT_COMMIT_MESSAGE_CHUNK_TOKENS: default chunk token budget (default: 0)

Default models (if not overridden):

  • OpenAI: gpt-5-mini
  • Google: gemini-2.5-flash
  • Ollama: gpt-oss:20b

AI-generated code notice

Parts of this project were created with assistance from AI tools (e.g. large language models). All AI-assisted contributions were reviewed and adapted by maintainers before inclusion. If you need provenance for specific changes, please refer to the Git history and commit messages.

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_message-0.8.0.tar.gz (16.1 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_message-0.8.0-py3-none-any.whl (16.5 kB view details)

Uploaded Python 3

File details

Details for the file git_commit_message-0.8.0.tar.gz.

File metadata

  • Download URL: git_commit_message-0.8.0.tar.gz
  • Upload date:
  • Size: 16.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.17 {"installer":{"name":"uv","version":"0.9.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for git_commit_message-0.8.0.tar.gz
Algorithm Hash digest
SHA256 863cfff1eb62bf8ff6ce04dcea13ef40d7c351201a6752b7c3c5b4b228edc8c6
MD5 344e860bcd58fd1b003c3cfc7ba025fa
BLAKE2b-256 684ce32b354ebf6a68e586d78d89136a4dc6b22a37bb4f9d94bfb1a75c193df6

See more details on using hashes here.

File details

Details for the file git_commit_message-0.8.0-py3-none-any.whl.

File metadata

  • Download URL: git_commit_message-0.8.0-py3-none-any.whl
  • Upload date:
  • Size: 16.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.17 {"installer":{"name":"uv","version":"0.9.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for git_commit_message-0.8.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e571b7cf08badbbaea60d4260199e69831b0e06842f71da8eedbbd6f142b3c76
MD5 104751bc4ad1d449c94353b87e74476b
BLAKE2b-256 20adeb965883476197f76cad9221aac15442304437d6199a5220e072f92e627b

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