Intelligent commit messages with sophisticated multi-step analysis
Git AI seamlessly integrates ChatGPT with git hooks to automate commit message generation based on your staged files. Using a sophisticated multi-step analysis process, it analyzes each file individually, calculates impact scores, and generates multiple commit message candidates before selecting the best one.
π§ Multi-Step Analysis - Sophisticated divide-and-conquer approach that analyzes files individually β‘ Lightning Fast - Rust-powered with parallel processing and intelligent optimization π― Smart Integration - Uses OpenAI's Assistant API, expertly tailored for git diffs π§ Contextual Learning - Maintains dedicated threads per project for improved relevance π Intelligent Fallbacks - Multiple fallback strategies ensure you always get meaningful messages π Local Optimization - Hosts exclusive assistant instance learning from all your projects
# Install Git AI
cargo install git-ai
# Set your OpenAI API key
git-ai config set openai-api-key sk-your-key-here
# Install the git hook in your repository
git-ai hook install
# Make changes, stage them, and commit without a message
git add .
git commit --all --no-edit
# β¨ Watch Git AI's multi-step analysis generate your perfect commit message!
Git AI uses a sophisticated multi-step analysis process:
βββββββββββββββ βββββββββββββββ βββββββββββββββ βββββββββββββββ βββββββββββββββ
β Git Commit ββββββΆβ Parse Diff ββββββΆβ Analyze ββββββΆβ Score ββββββΆβ Generate β
β (no msg) β β Files β β Files β β Files β β Messages β
βββββββββββββββ βββββββββββββββ βββββββββββββββ βββββββββββββββ βββββββββββββββ
β β β β
βΌ βΌ βΌ βΌ
βββββββββββββββ βββββββββββββββ βββββββββββββββ βββββββββββββββ
β auth.rs β β Lines: +50 β β Score: 0.95 β β Candidates: β
β test.rs β β Lines: -10 β β Score: 0.65 β β 1. "Add JWT"β
β main.rs β β Category: β β Score: 0.62 β β 2. "auth: β
βββββββββββββββ β source β βββββββββββββββ β impl" β
βββββββββββββββ βββββββββββββββ
β
βΌ
βββββββββββββββ
β Select β
β Best β
β Message β
βββββββββββββββ
-
Parse - Splits the git diff into individual files
- Handles different diff formats (standard, commit with hash, raw output)
- Extracts file paths, operation types, and diff content
- Supports added, modified, deleted, renamed, and binary files
-
Analyze - Examines each file in parallel for:
- Lines added/removed (counts actual +/- lines)
- File type categorization (source, test, config, docs, binary, build)
- Change significance and summary generation
- Uses OpenAI function calling for structured analysis
-
Score - Calculates impact scores based on:
- Operation type weights (add: 0.3, modify: 0.2, delete: 0.25, rename: 0.1, binary: 0.05)
- File category weights (source: 0.4, test: 0.2, config: 0.25, build: 0.3, docs: 0.1, binary: 0.05)
- Lines changed (normalized up to 0.3)
- Total score capped at 1.0
-
Generate - Creates multiple commit message candidates
- Action-focused style (e.g., "Add authentication")
- Component-focused style (e.g., "auth: implementation")
- Impact-focused style (e.g., "New feature for authentication")
- Respects max length constraints
-
Select - Chooses the best message based on:
- Highest impact files
- Overall change context
- Conventional commit format when appropriate
ββββββββββββββββββββ
β Multi-Step + API β ββββ Fail ββββ
ββββββββββ¬ββββββββββ β
β Success βΌ
βΌ ββββββββββββββββββββ
βββββββββββββ β Local Multi-Step β ββββ Fail ββββ
β Message β ββββββββββ¬ββββββββββ β
β Generated β ββββββββββββββββββββ Success βΌ
βββββββββββββ ββββββββββββββββββββ
β² β Single-Step API β
βββββββββββββββββββββββββββββββββββββββββββ΄βββββββββββββββββββ
Git AI automatically falls back through multiple strategies:
- Multi-Step with API - Full analysis using OpenAI's function calling
- Local Multi-Step - Local analysis without API (when API is unavailable)
- Single-Step API - Direct prompt-based generation as final fallback
This ensures you always get meaningful commit messages, even when the API is unavailable.
Uses a sophisticated divide-and-conquer approach that analyzes each file individually, calculates impact scores, and generates multiple commit message candidates before selecting the best one.
Leverages OpenAI's powerful Assistant API, expertly tailored to transform git diffs into insightful commit messages.
Maintains a dedicated thread for each project, allowing the assistant to build context over time and improve performance and message relevance with every commit.
Hosts an exclusive assistant instance on your machine, learning from all your projects to elevate the quality of commit messages throughout your development environment.
Automatically falls back to local analysis when API is unavailable, ensuring you always get meaningful commit messages.
cargo install git-ai
cargo install cargo-binstall
cargo binstall git-ai
git clone https://github.com/oleander/git-ai
cd git-ai
cargo install --path .
- Rust and Cargo installed on your machine
- Git repository
- OpenAI API key
# 1. Configure your API key
git-ai config set openai-api-key sk-your-key-here
# 2. Install the git hook
git-ai hook install
# 3. Start committing with multi-step analysis!
git add some-file.rs
git commit --all --no-edit # Git AI takes over here
# Choose your AI model
git-ai config set model gpt-4.1 # Latest (default)
git-ai config set model gpt-4o # Optimized, better quality
git-ai config set model gpt-4o-mini # Faster processing
git-ai config set model gpt-4 # Original GPT-4
# Customize output and performance
git-ai config set max-commit-length 72 # Limit message length
git-ai config set max-tokens 512 # Control API usage (default)
# Reset to defaults
git-ai config reset
git-ai hook install # Install hook in current repo
git-ai hook uninstall # Remove hook
git-ai hook reinstall # Reinstall hook
The project includes a Justfile with useful development commands:
# Install locally with debug symbols and setup hooks
just local-install
# Run integration tests in Docker
just integration-test
# Build Docker image
just docker-build
# Run GitHub Actions locally
just local-github-actions
# Build the project
cargo build
# Run tests
cargo test
# Install locally for development
cargo install --path .
# Quick local installation with hook setup
just local-install
// auth.rs (Score: 0.95 - High impact source file)
+ fn validate_jwt_token(token: &str) -> Result<Claims, AuthError> {
+ decode::<Claims>(token, &DecodingKey::from_secret("secret"), &Validation::default())
+ }
// test.rs (Score: 0.65 - Supporting test file)
+ #[test]
+ fn test_jwt_validation() {
+ assert!(validate_jwt_token("valid_token").is_ok());
+ }
Generated commit: Add JWT token validation with comprehensive error handling
// config.rs (Score: 0.82 - Important config change)
- if user.age > 18 {
+ if user.age >= 18 {
Generated commit: Correct age validation to include 18-year-olds in config
Setting | Description | Default |
---|---|---|
openai-api-key |
Your OpenAI API key | Required |
model |
AI model to use | gpt-4.1 |
max-tokens |
Maximum tokens per request | 512 |
max-commit-length |
Max commit message length | 72 |
- CLI Interface (
src/main.rs
) - Command-line interaction and configuration - Git Hook (
src/bin/hook.rs
) - Prepare-commit-msg hook integration - Multi-Step Analysis (
src/multi_step_analysis.rs
,src/multi_step_integration.rs
) - Sophisticated file analysis and scoring - Diff Processing (
src/hook.rs
) - Parallel processing and optimization - API Integration (
src/openai.rs
,src/ollama.rs
) - OpenAI and Ollama support - Function Calling (
src/function_calling.rs
) - Structured commit message generation
- Hook Installation - Symlinks executable to
.git/hooks/prepare-commit-msg
- Multi-Step Analysis - Parse β Analyze β Score β Generate β Select
- Intelligent Fallbacks - API β Local β Single-step as needed
- Performance Optimization - Parallel processing, token management, smart truncation
# Run all tests
cargo test
# Run integration tests
./scripts/integration-tests
# Test hook functionality
./scripts/hook-stress-test
# Run comprehensive test suite
./scripts/comprehensive-tests
- π Support for more AI providers (Anthropic, Cohere)
- π¨ Customizable commit message templates
- π Enhanced contextual learning across projects
- π Integration with popular Git GUIs
- π Multi-language commit message support
Q: How does multi-step analysis improve commit messages? A: By analyzing files individually and calculating impact scores, Git AI understands which changes are most significant and crafts messages that reflect the true purpose of your commit.
Q: What happens if the API is down? A: Git AI automatically falls back to local multi-step analysis, then single-step API if needed. You'll always get a meaningful commit message.
Q: Will this work with any Git repository? A: Yes! Git AI works with any Git repository. Just install the hook and you're ready to go.
Q: What if I want to write my own commit message?
A: Just use git commit -m "your message"
as usual. Git AI only activates when no message is provided.
Your feedback and contributions are welcome! Join our community to help improve Git AI by submitting issues, offering suggestions, or contributing code. See our contributing guidelines for more details.
Git AI is proudly open-sourced under the MIT License. See LICENSE for more details.
Made with β€οΈ by developers, for developers
β Star this repo if Git AI's multi-step analysis improves your Git workflow!