Automate semantic git commit messages using OpenAI. git-massage analyzes your staged changes and generates high-quality, convention-compliant commit messages, saving you time and ensuring a clean git history.
- Gitmoji Support: Commit messages with emojis! Because if your commit messages don't have emojis, how would anyone know how you feel?
✨ feat(auth): add OAuth2 login flow 🐛 fix(api): handle null response from upstream 📝 docs: update README with gitmoji examples - Zero-Friction: Automatically runs
git diff --cachedto analyze staged changes. - Conventional Commits: Generates messages in
<type>(<scope>): <subject>format (e.g.,feat(auth): add login endpoint). - Interactive Workflow:
- Commit: Accept the generated message immediately.
- Edit: Refine the message in your default editor (
$EDITOR). - Regenerate: Ask AI to try again if the first attempt isn't perfect.
- Smart Context: Automatically excludes lockfiles (
package-lock.json,uv.lock, etc.) to save tokens and reduce noise. - Configurable: Persists settings like API keys and model preferences in
~/.config/git-massage/config.toml.
- Python 3.12+
- uv (recommended)
# Clone the repository
git clone https://github.com/yourusername/git-massage.git
cd git-massage
# Install dependencies
uv sync
# Run via uv
uv run git-massage --helpFirst, configure your OpenAI API key. This will be saved to ~/.config/git-massage/config.toml.
uv run git-massage setupAlternatively, you can set the OPENAI_API_KEY environment variable.
Stage your changes as usual, then run the tool:
git add .
uv run git-massageThe tool will:
- Analyze your staged changes.
- Display a generated commit message.
- Prompt for action:
[c]ommit: Executegit commitwith the message.[e]dit: Open the message in your editor for manual tweaks.[r]egenerate: Request a new message from the AI.[q]uit: Exit without doing anything.
You can override configuration defaults via CLI flags:
# Use a specific model
uv run git-massage --model gpt-4-turbo
# Pass API key directly
uv run git-massage --api-key sk-...For seamless integration with editors like Neovim, use the --print-only flag. This mode:
- Prints only the raw commit message to stdout
- Redirects all logs and spinners to stderr
- Exits immediately after generation (no interactive prompt)
# Capture message to a file
uv run git-massage --print-only > commit_message.txt
# Use in a pipeline
git commit -m "$(uv run git-massage --print-only)"Use a terminal plugin like toggleterm.nvim to run the full interactive experience:
-- In your Neovim config (e.g., ~/.config/nvim/lua/config/keymaps.lua)
vim.keymap.set('n', '<leader>gm', '<cmd>TermExec cmd="git-massage"<CR>', {
desc = "Generate commit message with git-massage"
})Insert the generated message directly into your current buffer:
-- In your Neovim config
vim.api.nvim_create_user_command('GitMassage', function()
-- Generate message using --print-only mode
local handle = io.popen("git-massage --print-only 2>/dev/null")
local result = handle:read("*a")
handle:close()
-- Insert at cursor position
if result and result ~= "" then
vim.api.nvim_put(vim.split(result, "\n"), 'c', true, true)
else
vim.notify("Failed to generate commit message", vim.log.levels.ERROR)
end
end, {})
-- Bind to a key
vim.keymap.set('n', '<leader>gc', '<cmd>GitMassage<CR>', {
desc = "Insert git-massage commit message"
})Automatically populate Git commit messages in fugitive or vim-fugitive buffers:
-- Auto-populate commit message in git commit buffers
vim.api.nvim_create_autocmd("FileType", {
pattern = "gitcommit",
callback = function()
vim.keymap.set('n', '<leader>gm', function()
vim.cmd('0read !git-massage --print-only 2>/dev/null')
end, { buffer = true, desc = "Generate commit message" })
end,
})Configuration is stored in ~/.config/git-massage/config.toml.
openai_api_key = "sk-..."
model = "gpt-4o"
max_diff_lines = 500
exclude_files = ["*-lock.json", "*.lock", "go.sum", "*.svg"]
use_gitmoji = trueAvailable Options:
openai_api_key: Your OpenAI API key (can also useOPENAI_API_KEYenv var)model: OpenAI model to use (default: "gpt-4o")max_diff_lines: Maximum lines of diff to send to AIexclude_files: Glob patterns for files to exclude from diff (reduces noise and saves tokens)use_gitmoji: Enable emoji prefixes in commit messages (default:true)
This project uses uv for dependency management and ruff for linting.
# Install dependencies
uv sync
# Run tests
uv run pytest
# Lint and format
uv run ruff check .
uv run ruff format .There are other great AI-powered commit message tools in the ecosystem:
- OpenCommit - GitHub Action for improving commits with AI
- ai-commit - AI-powered commit message generator
