{"id":21201654,"url":"https://github.com/oleander/git-ai","last_synced_at":"2025-07-10T06:31:47.351Z","repository":{"id":213158899,"uuid":"703097783","full_name":"oleander/git-ai","owner":"oleander","description":"Git AI uses ChatGPT and git hook to generate commit messages based on the staged files. Leave the commit message empty and let Git AI do the work for you!","archived":false,"fork":false,"pushed_at":"2024-11-16T08:03:48.000Z","size":990,"stargazers_count":3,"open_issues_count":5,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-11-16T08:20:22.782Z","etag":null,"topics":["commit-messages","git-automation","git-hooks","openai-chatgpt","rust"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/oleander.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-10-10T15:33:54.000Z","updated_at":"2024-08-01T14:49:22.000Z","dependencies_parsed_at":"2023-12-19T01:18:11.907Z","dependency_job_id":"a68cb5d5-1002-4a83-a53e-bc9e8f0b7cc9","html_url":"https://github.com/oleander/git-ai","commit_stats":null,"previous_names":["oleander/git-ai"],"tags_count":41,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oleander%2Fgit-ai","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oleander%2Fgit-ai/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oleander%2Fgit-ai/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oleander%2Fgit-ai/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/oleander","download_url":"https://codeload.github.com/oleander/git-ai/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225622846,"owners_count":17498168,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["commit-messages","git-automation","git-hooks","openai-chatgpt","rust"],"created_at":"2024-11-20T20:10:22.347Z","updated_at":"2025-07-10T06:31:47.344Z","avatar_url":"https://github.com/oleander.png","language":"Rust","readme":"# 🤖 Git AI\n\n\u003e **Intelligent commit messages with sophisticated multi-step analysis**\n\n[![Rust](https://github.com/oleander/git-ai/actions/workflows/cd.yml/badge.svg)](https://github.com/oleander/git-ai/actions/workflows/cd.yml)\n[![Crates.io](https://img.shields.io/crates/v/git-ai.svg)](https://crates.io/crates/git-ai)\n[![License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)\n[![Downloads](https://img.shields.io/crates/d/git-ai?style=flat-square)](https://crates.io/crates/git-ai)\n[![Rust](https://img.shields.io/badge/rust-1.70%2B-orange?style=flat-square)](https://www.rust-lang.org)\n\n---\n\nGit 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.\n\n## ✨ Why Git AI?\n\n🧠 **Multi-Step Analysis** - Sophisticated divide-and-conquer approach that analyzes files individually\n⚡ **Lightning Fast** - Rust-powered with parallel processing and intelligent optimization\n🎯 **Smart Integration** - Uses OpenAI's Assistant API, expertly tailored for git diffs\n🧠 **Contextual Learning** - Maintains dedicated threads per project for improved relevance\n🔄 **Intelligent Fallbacks** - Multiple fallback strategies ensure you always get meaningful messages\n🏠 **Local Optimization** - Hosts exclusive assistant instance learning from all your projects\n\n## 🚀 Quick Start\n\n```bash\n# Install Git AI\ncargo install git-ai\n\n# Set your OpenAI API key\ngit-ai config set openai-api-key sk-your-key-here\n\n# Install the git hook in your repository\ngit-ai hook install\n\n# Make changes, stage them, and commit without a message\ngit add .\ngit commit --all --no-edit\n# ✨ Watch Git AI's multi-step analysis generate your perfect commit message!\n```\n\n## 🎬 How It Works\n\nGit AI uses a sophisticated multi-step analysis process:\n\n```\n┌─────────────┐     ┌─────────────┐     ┌─────────────┐     ┌─────────────┐     ┌─────────────┐\n│ Git Commit  │────▶│ Parse Diff  │────▶│  Analyze    │────▶│   Score     │────▶│  Generate   │\n│  (no msg)   │     │   Files     │     │   Files     │     │   Files     │     │  Messages   │\n└─────────────┘     └─────────────┘     └─────────────┘     └─────────────┘     └─────────────┘\n                           │                    │                    │                    │\n                           ▼                    ▼                    ▼                    ▼\n                    ┌─────────────┐     ┌─────────────┐     ┌─────────────┐     ┌─────────────┐\n                    │ auth.rs     │     │ Lines: +50  │     │ Score: 0.95 │     │ Candidates: │\n                    │ test.rs     │     │ Lines: -10  │     │ Score: 0.65 │     │ 1. \"Add JWT\"│\n                    │ main.rs     │     │ Category:   │     │ Score: 0.62 │     │ 2. \"auth:   │\n                    └─────────────┘     │   source    │     └─────────────┘     │    impl\"    │\n                                       └─────────────┘                           └─────────────┘\n                                                                                         │\n                                                                                         ▼\n                                                                                 ┌─────────────┐\n                                                                                 │   Select    │\n                                                                                 │    Best     │\n                                                                                 │  Message    │\n                                                                                 └─────────────┘\n```\n\n### Multi-Step Process\n\n1. **Parse** - Splits the git diff into individual files\n\n   - Handles different diff formats (standard, commit with hash, raw output)\n   - Extracts file paths, operation types, and diff content\n   - Supports added, modified, deleted, renamed, and binary files\n\n2. **Analyze** - Examines each file in parallel for:\n\n   - Lines added/removed (counts actual +/- lines)\n   - File type categorization (source, test, config, docs, binary, build)\n   - Change significance and summary generation\n   - Uses OpenAI function calling for structured analysis\n\n3. **Score** - Calculates impact scores based on:\n\n   - Operation type weights (add: 0.3, modify: 0.2, delete: 0.25, rename: 0.1, binary: 0.05)\n   - File category weights (source: 0.4, test: 0.2, config: 0.25, build: 0.3, docs: 0.1, binary: 0.05)\n   - Lines changed (normalized up to 0.3)\n   - Total score capped at 1.0\n\n4. **Generate** - Creates multiple commit message candidates\n\n   - Action-focused style (e.g., \"Add authentication\")\n   - Component-focused style (e.g., \"auth: implementation\")\n   - Impact-focused style (e.g., \"New feature for authentication\")\n   - Respects max length constraints\n\n5. **Select** - Chooses the best message based on:\n   - Highest impact files\n   - Overall change context\n   - Conventional commit format when appropriate\n\n### Intelligent Fallback Strategy\n\n```\n┌──────────────────┐\n│ Multi-Step + API │ ──── Fail ───┐\n└────────┬─────────┘              │\n         │ Success                ▼\n         ▼                 ┌──────────────────┐\n   ┌───────────┐           │ Local Multi-Step │ ──── Fail ───┐\n   │  Message  │           └────────┬─────────┘              │\n   │ Generated │ ◀──────────────────┘ Success                ▼\n   └───────────┘                                   ┌──────────────────┐\n         ▲                                         │ Single-Step API  │\n         └─────────────────────────────────────────┴──────────────────┘\n```\n\nGit AI automatically falls back through multiple strategies:\n\n1. **Multi-Step with API** - Full analysis using OpenAI's function calling\n2. **Local Multi-Step** - Local analysis without API (when API is unavailable)\n3. **Single-Step API** - Direct prompt-based generation as final fallback\n\nThis ensures you always get meaningful commit messages, even when the API is unavailable.\n\n## 🌟 Key Features\n\n### 🧠 **Multi-Step Analysis (Default)**\n\nUses 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.\n\n### 🎯 **Smart Integration**\n\nLeverages OpenAI's powerful Assistant API, expertly tailored to transform git diffs into insightful commit messages.\n\n### 📚 **Contextual Learning**\n\nMaintains a dedicated thread for each project, allowing the assistant to build context over time and improve performance and message relevance with every commit.\n\n### 🏠 **Local Optimization**\n\nHosts an exclusive assistant instance on your machine, learning from all your projects to elevate the quality of commit messages throughout your development environment.\n\n### 🛡️ **Intelligent Fallbacks**\n\nAutomatically falls back to local analysis when API is unavailable, ensuring you always get meaningful commit messages.\n\n## 📦 Installation\n\n### Option 1: Cargo (Recommended)\n\n```bash\ncargo install git-ai\n```\n\n### Option 2: Pre-compiled Binaries\n\n```bash\ncargo install cargo-binstall\ncargo binstall git-ai\n```\n\n### Option 3: From Source\n\n```bash\ngit clone https://github.com/oleander/git-ai\ncd git-ai\ncargo install --path .\n```\n\n### Prerequisites\n\n- Rust and Cargo installed on your machine\n- Git repository\n- OpenAI API key\n\n## 🎯 Usage\n\n### Basic Setup\n\n```bash\n# 1. Configure your API key\ngit-ai config set openai-api-key sk-your-key-here\n\n# 2. Install the git hook\ngit-ai hook install\n\n# 3. Start committing with multi-step analysis!\ngit add some-file.rs\ngit commit --all --no-edit  # Git AI takes over here\n```\n\n### Advanced Configuration\n\n```bash\n# Choose your AI model\ngit-ai config set model gpt-4.1       # Latest (default)\ngit-ai config set model gpt-4o        # Optimized, better quality\ngit-ai config set model gpt-4o-mini   # Faster processing\ngit-ai config set model gpt-4         # Original GPT-4\n\n# Customize output and performance\ngit-ai config set max-commit-length 72    # Limit message length\ngit-ai config set max-tokens 512          # Control API usage (default)\n\n# Reset to defaults\ngit-ai config reset\n```\n\n### Hook Management\n\n```bash\ngit-ai hook install      # Install hook in current repo\ngit-ai hook uninstall    # Remove hook\ngit-ai hook reinstall    # Reinstall hook\n```\n\n## 🛠️ Development\n\n### Using Justfile Commands\n\nThe project includes a Justfile with useful development commands:\n\n```bash\n# Install locally with debug symbols and setup hooks\njust local-install\n\n# Run integration tests in Docker\njust integration-test\n\n# Build Docker image\njust docker-build\n\n# Run GitHub Actions locally\njust local-github-actions\n```\n\n### Building from Source\n\n```bash\n# Build the project\ncargo build\n\n# Run tests\ncargo test\n\n# Install locally for development\ncargo install --path .\n\n# Quick local installation with hook setup\njust local-install\n```\n\n## 📖 Examples\n\n### Feature Addition with Multi-Step Analysis\n\n```diff\n// auth.rs (Score: 0.95 - High impact source file)\n+ fn validate_jwt_token(token: \u0026str) -\u003e Result\u003cClaims, AuthError\u003e {\n+     decode::\u003cClaims\u003e(token, \u0026DecodingKey::from_secret(\"secret\"), \u0026Validation::default())\n+ }\n\n// test.rs (Score: 0.65 - Supporting test file)\n+ #[test]\n+ fn test_jwt_validation() {\n+     assert!(validate_jwt_token(\"valid_token\").is_ok());\n+ }\n```\n\n**Generated commit:** `Add JWT token validation with comprehensive error handling`\n\n### Bug Fix Analysis\n\n```diff\n// config.rs (Score: 0.82 - Important config change)\n- if user.age \u003e 18 {\n+ if user.age \u003e= 18 {\n```\n\n**Generated commit:** `Correct age validation to include 18-year-olds in config`\n\n## ⚙️ Configuration Reference\n\n| Setting             | Description                | Default   |\n| ------------------- | -------------------------- | --------- |\n| `openai-api-key`    | Your OpenAI API key        | Required  |\n| `model`             | AI model to use            | `gpt-4.1` |\n| `max-tokens`        | Maximum tokens per request | `512`     |\n| `max-commit-length` | Max commit message length  | `72`      |\n\n## 🏗️ Architecture\n\n### Core Components\n\n- **CLI Interface** (`src/main.rs`) - Command-line interaction and configuration\n- **Git Hook** (`src/bin/hook.rs`) - Prepare-commit-msg hook integration\n- **Multi-Step Analysis** (`src/multi_step_analysis.rs`, `src/multi_step_integration.rs`) - Sophisticated file analysis and scoring\n- **Diff Processing** (`src/hook.rs`) - Parallel processing and optimization\n- **API Integration** (`src/openai.rs`, `src/ollama.rs`) - OpenAI and Ollama support\n- **Function Calling** (`src/function_calling.rs`) - Structured commit message generation\n\n### Key Workflows\n\n1. **Hook Installation** - Symlinks executable to `.git/hooks/prepare-commit-msg`\n2. **Multi-Step Analysis** - Parse → Analyze → Score → Generate → Select\n3. **Intelligent Fallbacks** - API → Local → Single-step as needed\n4. **Performance Optimization** - Parallel processing, token management, smart truncation\n\n## 🧪 Testing\n\n```bash\n# Run all tests\ncargo test\n\n# Run integration tests\n./scripts/integration-tests\n\n# Test hook functionality\n./scripts/hook-stress-test\n\n# Run comprehensive test suite\n./scripts/comprehensive-tests\n```\n\n## 🚀 Roadmap\n\n- [ ] 🌐 Support for more AI providers (Anthropic, Cohere)\n- [ ] 🎨 Customizable commit message templates\n- [ ] 📊 Enhanced contextual learning across projects\n- [ ] 🔄 Integration with popular Git GUIs\n- [ ] 🌍 Multi-language commit message support\n\n## ❓ FAQ\n\n**Q: How does multi-step analysis improve commit messages?**\nA: 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.\n\n**Q: What happens if the API is down?**\nA: Git AI automatically falls back to local multi-step analysis, then single-step API if needed. You'll always get a meaningful commit message.\n\n**Q: Will this work with any Git repository?**\nA: Yes! Git AI works with any Git repository. Just install the hook and you're ready to go.\n\n**Q: What if I want to write my own commit message?**\nA: Just use `git commit -m \"your message\"` as usual. Git AI only activates when no message is provided.\n\n## 🤝 Contributing\n\nYour 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](CONTRIBUTING.md) for more details.\n\n## 📜 License\n\nGit AI is proudly open-sourced under the MIT License. See [LICENSE](LICENSE) for more details.\n\n---\n\n**Made with ❤️ by developers, for developers**\n\n[⭐ Star this repo](https://github.com/oleander/git-ai) if Git AI's multi-step analysis improves your Git workflow!\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foleander%2Fgit-ai","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foleander%2Fgit-ai","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foleander%2Fgit-ai/lists"}