A tool that helps generate meaningful commit messages for your Git repositories using LLMs.
You can install this package using Homebrew:
brew install rtuin/tools/prepare-commit-msg-gen
After installing the package, you need to set up the prepare-commit-msg hook in your Git repository:
-
Navigate to your Git repository:
cd your-repository
-
Create a new prepare-commit-msg hook:
mkdir -p .git/hooks echo '#!/bin/sh prepare-commit-msg-gen "$1"' > .git/hooks/prepare-commit-msg chmod +x .git/hooks/prepare-commit-msg
Once installed and set up, the hook will automatically run every time you create a new commit. It will analyze your changes and suggest a meaningful commit message.
The tool can be configured using environment variables:
PREPARE_COMMIT_MSG_GEN_LLM_PROVIDER
: Choose the LLM provider to use (default: "anthropic")- Supported values: "anthropic", "ollama", "openai"
PREPARE_COMMIT_MSG_GEN_LLM_MODEL
: Specify the model to use- For Ollama: defaults to "qwen2.5-coder:7b"
- For OpenAI: defaults to "gpt-4o"
- For Anthropic: defaults to "claude-3-5-sonnet-latest"
PREPARE_COMMIT_MSG_GEN_OLLAMA_BASE_URL
: Set the base URL for your Ollama instance (default: "http://localhost:11434")
OPENAI_API_KEY
: Your OpenAI API key (required when using OpenAI provider)
ANTHROPIC_API_KEY
: Your Anthropic API key (required when using Anthropic provider)
If the hook is not running when you make commits, ensure that:
-
The hook is installed in the correct hooks directory. Git uses the directory specified by
core.hooksPath
configuration. By default, this is.git/hooks/
in your repository. You can check your hooks path with:git config core.hooksPath
-
If you've configured a custom hooks path, make sure to install the hook in that directory instead of
.git/hooks/
. -
The hook file has executable permissions:
chmod +x <hooks-path>/prepare-commit-msg
To install the package locally for development:
-
Clone the repository:
git clone https://github.com/rtuin/prepare-commit-msg-gen.git cd prepare-commit-msg-gen
-
Install Poetry if you haven't already: https://python-poetry.org/docs/#installation
-
Install the package in editable mode:
poetry install poetry build pip install -e .
-
Test the package:
touch test-message.txt prepare-commit-msg-gen test-message.txt
To run tests, use:
poetry run pytest
This project is licensed under the MIT License - see the LICENSE file for details.