AI-powered Git commit message generator that analyzes your staged changes and outputs conventional commit messages.
- Generates 10 commit message suggestions from your staged diff
- Providers: GitHub Copilot (default), OpenAI
- Interactive config to pick provider/model and set keys
- Simple output suitable for piping into TUI menus (one message per line)
go install github.com/m7medvision/lazycommit@latestOr build from source:
git clone https://github.com/m7medvision/lazycommit.git
cd lazycommit
go build -o lazycommit main.go- Root command:
lazycommit - Subcommands:
lazycommit commit— prints 10 suggested commit messages to stdout, one per line, based ongit diff --cached.lazycommit config get— prints the active provider and model.lazycommit config set— interactive setup for provider, API key, and model.
Exit behaviors:
- If no staged changes: prints "No staged changes to commit." and exits 0.
- On config/LLM errors: prints to stderr and exits non‑zero.
Generate suggestions after staging changes:
git add .
lazycommit commitPipe the first suggestion to commit (bash example):
MSG=$(lazycommit commit | sed -n '1p')
[ -n "$MSG" ] && git commit -m "$MSG"Pick interactively with fzf:
git add .
lazycommit commit | fzf --prompt='Pick commit> ' | xargs -r -I {} git commit -m "{}"lazycommit uses a two-file configuration system to separate sensitive provider settings from shareable prompt configurations:
Contains API keys, tokens, and provider-specific settings. Do not share this file.
active_provider: copilot # default if a GitHub token is found
providers:
copilot:
api_key: "$GITHUB_TOKEN" # Uses GitHub token; token is exchanged internally
model: "gpt-4o" # or "openai/gpt-4o"; both accepted
# endpoint_url: "https://api.githubcopilot.com" # Optional - uses default if not specified
openai:
api_key: "$OPENAI_API_KEY"
model: "gpt-4o"
# endpoint_url: "https://api.openai.com/v1" # Optional - uses default if not specified
# Custom provider example (e.g., local Ollama):
# local:
# api_key: "not-needed"
# model: "llama3.1:8b"
# endpoint_url: "http://localhost:11434/v1"Contains prompt templates and message configurations. Safe to share in dotfiles and Git.
This file is automatically created on first run with sensible defaults:
system_message: "You are a helpful assistant that generates git commit messages."
commit_message_template: "Based on the following git diff, generate 10 conventional commit messages. Each message should be on a new line, without any numbering or bullet points:\n\n%s"You can configure custom API endpoints for any provider, which is useful for:
- Local AI models: Ollama, LM Studio, or other local inference servers
- Enterprise proxies: Internal API gateways or proxy servers
- Alternative providers: Any OpenAI-compatible API endpoint
The endpoint_url field is optional. If not specified, the official endpoint for that provider will be used.
Ollama (local):
active_provider: openai # Use openai provider for Ollama compatibility
providers:
openai:
api_key: "ollama" # Ollama doesn't require real API keys
model: "llama3.1:8b"
endpoint_url: "http://localhost:11434/v1"Because lazycommit commit prints plain lines, it plugs nicely into menu UIs.
Add this to ~/.config/lazygit/config.yml:
customCommands:
- key: "<c-a>" # ctrl + a
description: "pick AI commit"
command: 'git commit -m "{{.Form.Msg}}"'
context: "files"
prompts:
- type: "menuFromCommand"
title: "ai Commits"
key: "Msg"
command: "lazycommit commit"
filter: '^(?P<raw>.+)$'
valueFormat: "{{ .raw }}"
labelFormat: "{{ .raw | green }}"This config will allows you to edit the commit message after picking from lazycommit suggestions.
- key: "<c-b>" # ctrl + b
description: "Pick AI commit (edit before committing)"
context: "files"
command: >
bash -c 'msg="{{.Form.Msg}}"; echo "$msg" > .git/COMMIT_EDITMSG && ${EDITOR:-nvim} .git/COMMIT_EDITMSG && if [ -s .git/COMMIT_EDITMSG ]; then
git commit -F .git/COMMIT_EDITMSG;
else
echo "Commit message is empty, commit aborted.";
fi'
prompts:
- type: "menuFromCommand"
title: "ai Commits"
key: "Msg"
command: "lazycommit commit"
filter: '^(?P<raw>.+)$'
valueFormat: "{{ .raw }}"
labelFormat: "{{ .raw | green }}"
output: terminal- "No staged changes to commit." — run
git addfirst. - "API key not set" — set the appropriate key in
.lazycommit.yamlor env var and rerun. - Copilot errors about token exchange — ensure your GitHub token has models scope or is valid; try setting
GITHUB_TOKEN.
MIT