AI-powered commit message generator using local LLMs via Ollama. Generate meaningful, conventional commit messages automatically from your staged changes.
- π Local AI: Uses Ollama for privacy and offline capability
- π Conventional Commits: Follows industry-standard commit message format
- β‘ Fast: Optimized for quick generation with model caching
- π§ Flexible: Works as standalone CLI or integrated git hooks
- π― Smart: Analyzes actual code changes, not just file names
- βοΈ Configurable: Customize models, prompts, and behavior
- Ollama installed and running
- Git repository
- Go 1.21+ (for building from source)
# Using go install
go install github.com/pesnik/gitai@latest
# Or download from releases
curl -L https://github.com/pesnik/gitai/releases/latest/download/gitai-linux-amd64 -o gitai
chmod +x gitai
sudo mv gitai /usr/local/bin/# Download recommended model
ollama pull codellama:7b
# Or use a smaller model for faster generation
ollama pull llama3:8b# Stage your changes
git add .
# Generate commit message
gitai generate
# Use the generated message
git commit -m "$(gitai generate)"# Install git hooks in current repository
gitai install
# Now git commit will automatically generate messages
git add .
git commit # Opens editor with AI-generated messagegitai generate # Generate commit message for staged changes
gitai install # Install git hooks in current repo
gitai uninstall # Remove git hooks
gitai config # Show current configuration
gitai config set <key> <value> # Set configuration option
gitai version # Show version information# Set Ollama model
gitai config set model codellama:7b
# Set Ollama host (if not default)
gitai config set host http://localhost:11434
# Customize prompt template
gitai config set prompt "Custom prompt template..."
# Set max diff size (in lines)
gitai config set max-diff-lines 500GitAI stores configuration in ~/.gitai/config.yaml:
model: "codellama:7b"
host: "http://localhost:11434"
timeout: 30
max_diff_lines: 500
prompt_template: |
Analyze this git diff and generate a concise commit message following conventional commits format:
{diff}
Rules:
- Start with type: feat, fix, docs, style, refactor, test, chore
- Include scope in parentheses if applicable
- Use present tense, imperative mood
- Keep subject line under 72 characters
- No period at the end of subject line
Generate only the commit message, no explanation.# Adding a new feature
feat(auth): add OAuth2 login integration
# Fixing a bug
fix(parser): handle null values in JSON response
# Refactoring code
refactor(utils): extract string validation to separate function
# Updating documentation
docs(readme): add installation instructions for Windows
# Adding tests
test(auth): add unit tests for login validation# Your typical workflow
git add src/auth.go
git commit
# Editor opens with: "feat(auth): add JWT token validation"
# Edit if needed, save and closeCreate custom prompt templates for specific project needs:
gitai config set prompt "$(cat <<EOF
You are a senior developer writing commit messages for a React application.
Analyze this diff and create a commit message that:
- Follows conventional commits
- Mentions component names when relevant
- Includes performance impact if applicable
Diff:
{diff}
Generate only the commit message:
EOF
)"Switch between models for different scenarios:
# Fast model for quick commits
gitai config set model llama3:8b
# Detailed model for complex changes
gitai config set model codellama:13bAdd to your .gitconfig:
[alias]
ai = !gitai generate
aic = !git add . && git commit -m "$(gitai generate)"Ollama not responding
# Check if Ollama is running
ollama list
# Start Ollama if needed
ollama serveModel not found
# Pull the model
ollama pull codellama:7b
# List available models
ollama listLarge diffs timing out
# Reduce max diff size
gitai config set max-diff-lines 200
# Or use a smaller/faster model
gitai config set model llama3:8bGenerated messages are poor quality
# Try a different model
gitai config set model codellama:13b
# Or customize the prompt
gitai config set prompt "Your custom prompt here..."git clone https://github.com/pesnik/gitai.git
cd gitai
go build -o gitai ./cmd/gitaigo test ./...- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'feat: add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
MIT License - see LICENSE file for details.
- Ollama for providing local LLM capabilities
- Conventional Commits for the commit message standard
- The Go community for excellent tooling and libraries
Made with β€οΈ for developers who want better commit messages without sacrificing privacy