π€ Git AI
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.
β¨ Why Git AI?
π§ 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
π Quick Start
# Install Git AI
# Set your OpenAI API key
# Install the git hook in your repository
# Make changes, stage them, and commit without a message
# β¨ Watch Git AI's multi-step analysis generate your perfect commit message!
π¬ How It Works
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 β
βββββββββββββββ
Multi-Step Process
-
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
Intelligent Fallback Strategy
ββββββββββββββββββββ
β 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.
π Key Features
π§ Multi-Step Analysis (Default)
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.
π― Smart Integration
Leverages OpenAI's powerful Assistant API, expertly tailored to transform git diffs into insightful commit messages.
π Contextual Learning
Maintains a dedicated thread for each project, allowing the assistant to build context over time and improve performance and message relevance with every commit.
π Local Optimization
Hosts an exclusive assistant instance on your machine, learning from all your projects to elevate the quality of commit messages throughout your development environment.
π‘οΈ Intelligent Fallbacks
Automatically falls back to local analysis when API is unavailable, ensuring you always get meaningful commit messages.
π¦ Installation
Option 1: Cargo (Recommended)
Option 2: Pre-compiled Binaries
Option 3: From Source
Prerequisites
- Rust and Cargo installed on your machine
- Git repository
- OpenAI API key
π― Usage
Basic Setup
# 1. Configure your API key
# 2. Install the git hook
# 3. Start committing with multi-step analysis!
Advanced Configuration
# Choose your AI model
# Customize output and performance
# Reset to defaults
Hook Management
π οΈ Development
Using Justfile Commands
The project includes a Justfile with useful development commands:
# Install locally with debug symbols and setup hooks
# Run integration tests in Docker
# Build Docker image
# Run GitHub Actions locally
Building from Source
# Build the project
# Run tests
# Install locally for development
# Quick local installation with hook setup
π Examples
Feature Addition with Multi-Step Analysis
// 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
Bug Fix Analysis
// 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
βοΈ Configuration Reference
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 |
ποΈ Architecture
Core Components
- 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
Key Workflows
- 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
π§ͺ Testing
# Run all tests
# Run integration tests
# Test hook functionality
# Run comprehensive test suite
π Roadmap
- π 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
β FAQ
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.
π€ Contributing
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.
π License
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!