AIGitCommit is a command-line tool that generates meaningful, semantic commit messages from your staged Git changes using AI.
It inspects your diffs, summarizes the intent of your changes, and produces clear, concise commit messages that follow the Conventional Commits specification.
- Conventional Commits Specification
- Understanding Semantic Commit Messages
- Commit Message Best Practices
Contributions are welcome! Please feel free to submit issues, feature requests, or pull requests on GitHub.
This project is licensed under the MIT License. See the LICENSE file for details.
- AI-Powered Commit Messages: Automatically generates meaningful, semantic commit messages from staged Git changes
- Conventional Commits: Follows the Conventional Commits specification for consistent, structured messages
- Multiple Output Formats:
- Human-readable table view (default)
- JSON format for CI/CD integration and automation
- Plain text output
- Flexible Workflow:
- Direct commit with
--commitflag - Copy to clipboard with
--copy-to-clipboard - Git hook integration for automatic message generation
- Direct commit with
- Interactive & Non-Interactive: Confirmation prompts by default, skip with
--yesfor scripting - Security & Performance: Uses libgit2 via the
git2crate, avoiding external git command execution - Multi-Provider Support: Compatible with OpenAI and other OpenAI-compatible APIs (Azure OpenAI, local models, etc.)
- Flexible Configuration:
- Environment variables for API settings
- Git config for repository-specific or global settings
- Configurable API base URL, token, proxy, and timeouts
- Sign-off Support: Auto sign-off via
AIGITCOMMIT_SIGNOFFenvironment variable orgit config aigitcommit.signoff - Proxy Support: HTTP and SOCKS5 proxies via
OPENAI_API_PROXY
AIGitCommit streamlines your commit workflow by:
- Analyzing Changes: Inspects staged changes using
git diff --cached - Understanding Context: Examines recent commit history for stylistic consistency
- AI Generation: Sends diffs to an OpenAI-compatible model with carefully crafted prompts
- Structured Output: Generates commit messages following Conventional Commits specification
- User Review: Presents the message for review and optional editing
The tool uses libgit2 for secure, efficient Git operations without spawning external processes. It automatically filters out common noise files (lock files, generated code) to focus on meaningful changes.
cargo install aigitcommitFor the latest development version:
cargo install --git https://github.com/mingcheng/aigitcommit.gitBoth commands will download, compile, and install the binary to your Cargo bin directory (typically ~/.cargo/bin). Ensure this directory is in your PATH.
Run AIGitCommit in Docker without installing the binary locally.
Read-only mode (generate message only):
docker run \
--rm \
-v $PWD:/repo:ro \
-e OPENAI_API_BASE='<api base>' \
-e OPENAI_API_TOKEN='<api token>' \
-e OPENAI_MODEL_NAME='<model name>' \
-e OPENAI_API_PROXY='<proxy if needed>' \
ghcr.io/mingcheng/aigitcommitInteractive mode (with --commit flag):
docker run \
--rm \
-it \
-v $PWD:/repo:rw \
-e OPENAI_API_BASE='<api base>' \
-e OPENAI_API_TOKEN='<api token>' \
-e OPENAI_MODEL_NAME='<model name>' \
-e OPENAI_API_PROXY='<proxy if needed>' \
ghcr.io/mingcheng/aigitcommit --commit --yesNote: Use --yes to skip interactive confirmations in non-TTY environments.
AIGitCommit includes a prepare-commit-msg hook that automatically generates commit messages during your workflow.
Quick install (recommended)
Install into the current repository:
aigitcommit install-hook .Install into a specific repository:
aigitcommit install-hook /path/to/repoPrerequisite: aigitcommit is installed and available in your PATH.
Prerequisites
aigitcommitmust be installed and available in yourPATH- Configure required environment variables before committing (see Configuration)
Manual install (alternative)
cp hooks/prepare-commit-msg .git/hooks/prepare-commit-msg
chmod +x .git/hooks/prepare-commit-msgDisable for a single commit: Use git commit --no-verify to bypass the hook.
Global installation (optional)
Use Git templates so new repos have the hook:
mkdir -p ~/.git-template/hooks
cp hooks/prepare-commit-msg ~/.git-template/hooks/prepare-commit-msg
chmod +x ~/.git-template/hooks/prepare-commit-msg
git config --global init.templateDir ~/.git-templateApply to an existing repo (either copy the file or re-init):
cp ~/.git-template/hooks/prepare-commit-msg <repo>/.git/hooks/
# or
cd <repo> && git initHook behavior (summary)
- Triggers on
git commitwith no message or with-m "". - Skips merge/rebase/cherry-pick and commits with an existing message.
Troubleshooting
- "No staged changes detected": Run
git addto stage your changes before committing - "aigitcommit is not installed": Ensure the binary is in your
PATHor install it first - Missing configuration error: Export required environment variables (
OPENAI_API_TOKEN, etc.) in your shell - Hook output too verbose: Redirect stderr in your Git configuration:
git config core.hookStderr false
Configure AIGitCommit by setting these environment variables (in your shell profile, .bashrc, .zshrc, etc.):
Required:
OPENAI_API_TOKEN: Your OpenAI-compatible API authentication tokenOPENAI_API_BASE: API endpoint URL (e.g.,https://api.openai.com/v1or your provider's URL)OPENAI_MODEL_NAME: Model identifier (e.g.,gpt-4,gpt-3.5-turbo, or provider-specific models)
Optional:
OPENAI_API_PROXY: HTTP/SOCKS5 proxy URL (e.g.,http://127.0.0.1:1080,socks5://127.0.0.1:1086)OPENAI_API_TIMEOUT: Request timeout in seconds (default: 30)OPENAI_API_MAX_TOKENS: Maximum tokens in response (default: model-specific)AIGITCOMMIT_SIGNOFF: Enable auto sign-off (true,1,yes,on)
Example configuration:
# ~/.bashrc or ~/.zshrc
export OPENAI_API_TOKEN="sk-..."
export OPENAI_API_BASE="https://api.openai.com/v1"
export OPENAI_MODEL_NAME="gpt-4"
export OPENAI_API_PROXY="http://127.0.0.1:1080" # Optional
export AIGITCOMMIT_SIGNOFF="true" # OptionalYou can also enable sign-off via Git configuration (takes precedence over environment variables):
# Repository-specific
git config aigitcommit.signoff true
# Global (all repositories)
git config --global aigitcommit.signoff trueCheck your environment setup:
# Verify all environment variables
aigitcommit --check-env
# Test API connectivity and model availability
aigitcommit --check-model
# Show all available options
aigitcommit --helpRun AIGitCommit in a Git repository with staged changes:
# In the current repository
aigitcommit
# Specify a different repository path
aigitcommit /path/to/repoThe tool will:
- Analyze your staged changes (
git diff --cached) - Generate a Conventional Commit message using AI
- Display the result in table format (default)
Output Formats:
- Default: Table view (easy to read)
--json: JSON output (for CI/automation)--no-table: Plain text output
Actions:
--commit: Automatically commit with the generated message--copy-to-clipboard: Copy the message to clipboard--yes: Skip confirmation prompts (useful for scripting)--signoff: AppendSigned-off-byline to the commit
Diagnostics:
--check-env: Verify environment variable configuration--check-model: Test API connectivity and model availability--help: Show all available options
Generate and review message:
aigitcommitAuto-commit without confirmation:
aigitcommit --commit --yesCopy message to clipboard:
aigitcommit --copy-to-clipboardJSON output for CI pipelines:
aigitcommit --json | jq '.title'Commit with sign-off:
aigitcommit --commit --signoffTypical workflow:
# Stage your changes
git add .
# Generate and review commit message
aigitcommit
# Or commit directly
aigitcommit --commit
# Or use the Git hook (if installed)
git commit # Hook generates message automaticallyThis project is licensed under the MIT License. See the LICENSE file for details.
