A standalone CLI tool that generates conventional commit messages using AI. Commitgen analyzes your git changes and creates descriptive, properly formatted commit messages automatically.
- Features
- Installation
- Usage
- Configuration
- Output Format
- Development
- Advanced Usage
- Contributing
- Requirements
- License
- Multiple Analysis Modes: Staged files, all changes, or untracked files
- Conventional Commits: Follows
type(scope): description
format - Smart Scope Detection: Automatically extracts service/module from file paths
- Multiple AI Providers: Support for Claude, Gemini, and Copilot
- Interactive: Preview and confirm commit messages before committing
curl -fsSL https://raw.githubusercontent.com/FreePeak/commitgen/main/install-package.sh | bash
This script automatically detects your OS and installs commitgen using the best available package manager.
brew tap FreePeak/tap
brew install commitgen
go install github.com/FreePeak/commitgen@latest
# Download and install .deb package
curl -fsSL https://raw.githubusercontent.com/FreePeak/commitgen/main/install-package.sh | METHOD=2 bash
# Using yay (recommended)
yay -S commitgen
# Or using paru
paru -S commitgen
# Or manually
git clone https://aur.archlinux.org/commitgen.git
cd commitgen
makepkg -si
sudo snap install commitgen
# Pull from GitHub Container Registry
docker pull ghcr.io/freepeak/commitgen:latest
# Run with volume mount
docker run --rm -v $(pwd):/app -w /app ghcr.io/freepeak/commitgen:latest commit staged
# Download the latest binary for your platform
curl -fsSL https://raw.githubusercontent.com/FreePeak/commitgen/main/install.sh | bash
git clone https://github.com/FreePeak/commitgen.git
cd commitgen
go build -o commitgen main.go
./commitgen install
# Clone and build in one command
git clone https://github.com/FreePeak/commitgen.git && cd commitgen && go build -o commitgen main.go && ./commitgen install
# Generate commit message from staged files (default)
commitgen
# Or explicitly
commitgen commit staged
commitgen commit s
# Generate from all changes (stages + commits)
commitgen commit all
commitgen commit a
# Generate from untracked files only
commitgen commit untracked
commitgen commit u
# Use Claude (default)
commitgen
commitgen --provider claude
# Use Gemini
commitgen --provider gemini
# Use Copilot
commitgen --provider copilot
# Use provider with specific subcommand
commitgen commit staged --provider gemini
commitgen commit all --provider copilot
# Stage your changes first
git add .
# Generate and commit with AI
commitgen
# Output:
# Generated commit message:
# "feat(service:rating): add get RestaurantQuickReview with caching"
#
# Do you want to use this commit message? [y/N] y
# Committed successfully!
# Using different AI provider
commitgen --provider gemini commit staged
# Output:
# Generated commit message:
# "fix(api:user): resolve null pointer in validation"
#
# Do you want to use this commit message? [y/N] y
# Committed successfully!
Commitgen uses your existing AI CLI commands and configuration. Make sure you have:
- AI CLI commands available in your PATH:
claude
for Claudegemini
for Geminicopilot
for Copilot
- Proper API keys configured for your chosen AI provider
- Git repository initialized
Commitgen generates conventional commit messages following this format:
type(scope): description
Types:
feat
: New featurefix
: Bug fixdocs
: Documentation changesstyle
: Code style changes (formatting, etc.)refactor
: Code refactoringtest
: Test additions/changeschore
: Maintenance tasks
Examples:
feat(service:rating): add get RestaurantQuickReview with caching
fix(api:user): resolve null pointer in validation
docs(readme): update setup instructions
go build -o commitgen main.go
go test ./...
go build -o commitgen main.go
./commitgen install
- Go 1.19+
- Git
- AI CLI commands with proper API configuration:
claude
for Claudegemini
for Geminicopilot
for Copilot
- Unix-like system (Linux, macOS)
Commitgen automatically analyzes git changes and provides context to the AI model:
- Staged changes: Uses
git diff --cached
to review staged modifications - All changes: Combines modified files and untracked files for comprehensive analysis
- Untracked files: Reads content of new files that haven't been added to git yet
"not in a git repository"
- Make sure you're in a directory with a
.git
folder - Run
git init
if starting a new repository
"no changes found to analyze"
- Stage some files with
git add <files>
- Or use
commitgen commit all
to include unstaged changes - Use
commitgen commit untracked
for new files
"failed to call [provider] API"
- Ensure the AI CLI command is available in your PATH
- Verify API keys are properly configured
- Test the AI CLI command directly:
claude
orgemini
orcopilot
Claude (Default)
# Install claude
pip install claude
# Configure API key in environment
export ANTHROPIC_API_KEY="your-key-here"
Gemini
# Install Gemini CLI
npm install -g @google-cloud/vertexai
# Configure authentication
gcloud auth application-default login
Copilot
# Install GitHub CLI with Copilot extension
gh extension install github/gh-copilot
# Login to GitHub
gh auth login
You can integrate commitgen into your git workflow using hooks:
# Set up prepare-commit-msg hook
echo '#!/bin/bash
if [ -z "$2" ]; then
./commitgen --provider claude > .git/COMMIT_EDITMSG.tmp
if [ -f .git/COMMIT_EDITMSG.tmp ]; then
cat .git/COMMIT_EDITMSG.tmp > "$1"
rm .git/COMMIT_EDITMSG.tmp
fi
fi' > .git/hooks/prepare-commit-msg
chmod +x .git/hooks/prepare-commit-msg
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
commitgen commit staged
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
MIT License - see LICENSE file for details.