Skip to main content

AI automatic commit message

Project description

GitAI

Overview

You know how sometimes writing a good Git commit message feels like a chore, especially when you've got a bunch of small changes? This tool, GitAI, takes the pain out of it by automatically generating clear, concise commit messages for you based on your staged changes. It looks at what you've actually changed and suggests a message that truly reflects your work, so you can focus on coding.

Features

Here's what GitAI can do for you:

  • Intelligent Commit Message Generation: Automatically creates relevant commit messages by analyzing your staged Git changes.
  • Semantic Diff Analysis: Goes beyond raw diffs to understand the high-level meaning of your changes, identifying new functions, class updates, dependency changes, and more.
  • Conventional Commits Support: Generate messages in the widely adopted Conventional Commits format (type(scope): message), helping keep your commit history clean and parseable.
  • Configurable Output: Customize the commit message style, title length, and whether to include a body in the generated message.
  • Breaking Change Detection: Offers hints for potential breaking changes, prompting you to review and confirm impact on public APIs.
  • Flexible LLM Integration: Uses litellm to support various large language models (LLMs) for message generation, allowing you to switch providers easily.
  • Interactive Workflow: Provides options to accept, reject, or retry message generation if the initial suggestion isn't quite right.
  • Automatic Committing: Option to automatically commit with the generated message, streamlining your workflow.

Getting Started

Let's get you set up to use GitAI.

Installation

  1. Clone the Repository:

    git clone https://github.com/yourusername/gitai.git # Replace with your repo URL
    cd gitai
    
  2. Ensure Python 3.10: This project requires Python 3.10 or newer. You can check your Python version with python --version.

  3. Install Dependencies: GitAI is designed as a Python package. Install it in editable mode:

    pip install -e .
    

Environment Variables

Before you can run GitAI, you'll need to set up your AI provider API key and chosen LLM model. Create a .env file in the root of your project (where pyproject.toml is) with the following variables:

AI_KEY=your_api_key_here
LLM_MODEL=gemini/gemini-2.5-flash # Or your preferred model like "openai/gpt-4o"
  • AI_KEY: Your API key for the chosen LLM provider (e.g., Google Gemini, OpenAI).
  • LLM_MODEL: The identifier for the LLM model you want to use. litellm supports many, so pick one that fits your needs. Examples include gemini/gemini-1.5-flash, openai/gpt-3.5-turbo, etc.

💡 Tip: For detailed instructions on configuring different AI providers (Google Gemini, OpenAI, Anthropic, Groq, etc.), see the AI Model Configuration Guide.

You can also create a config.json file to customize GitAI's behavior:

{
  "style": "conventional",
  "max_title_length": 72,
  "include_body": true,
  "custom_instructions": "",
  "auto_commit": false,
  "retry":3
}

Usage

Using GitAI is pretty straightforward. Just make your changes, stage them, and let GitAI suggest a commit message.

  1. Stage Your Changes: Just like you normally would, add your changes to the staging area:

    git add .
    
  2. Generate a Commit Message: Now, run GitAI from your terminal. It'll analyze your staged changes and suggest a message.

    gitai
    

    GitAI will print a suggested commit message and ask you if you'd like to use it. If you're happy, type y and press Enter. If not, you can type n to get another suggestion (up to 3 retries by default) or exit.

    🔍 Generating commit message...
    
    ✨ Suggested Commit Message:
    
    feat(cli): add interactive retry for commit messages
    
    - Implemented a retry mechanism for generating commit messages.
    - Allows users to request new messages if the initial suggestion is not suitable.
    - Configurable `retry` count in `config.json`.
    
    --------------------------------------------------
    👉 Use this commit message? (y/n): y
    ✅ Commit created.
    
  3. Automatic Committing: If you've set "auto_commit": true in your config.json, GitAI will automatically commit with the generated message without asking for confirmation.

Logging & Error Handling

GitAI includes comprehensive logging and error handling with a focus on security:

  • Secure Logging: All logs are automatically sanitized to prevent sensitive data (API keys, passwords, tokens) from being written to log files.
  • Custom Exceptions: Clear, actionable error messages with suggestions for resolution.
  • Debug-Friendly: Detailed logs are stored in the logs/ directory for troubleshooting.

For detailed information on configuring logging, understanding error types, and best practices, see the Logging and Error Handling Guide.

Technologies Used

Technology Description Link
Python The primary programming language used for the project. Python
Unidiff Library for parsing and working with unified diff output. Unidiff
LiteLLM A universal API for all Large Language Models, simplifying AI integration. LiteLLM
Rich A Python library for rich text and beautiful formatting in the terminal. Rich
Setuptools Standard library for packaging Python projects. Setuptools

Contributing

We'd love for you to contribute to GitAI! If you have ideas for new features, find a bug, or want to improve the codebase, please feel free to:

  1. Fork the Repository: Start by forking the project to your own GitHub account.
  2. Create a New Branch: Make a new branch for your changes (e.g., feature/add-new-llm, bugfix/parsing-issue).
  3. Implement Your Changes: Write your code, ensuring it follows the existing style and conventions.
  4. Write Tests: If applicable, add or update tests to cover your changes.
  5. Submit a Pull Request: Open a pull request against the main branch of this repository. Please provide a clear description of your changes and why they're beneficial.

Author Info


Python 3.10+ Conventional Commits Made with LiteLLM

Readme was generated by Dokugen

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ojogu_gitai-0.1.0.tar.gz (37.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ojogu_gitai-0.1.0-py3-none-any.whl (41.3 kB view details)

Uploaded Python 3

File details

Details for the file ojogu_gitai-0.1.0.tar.gz.

File metadata

  • Download URL: ojogu_gitai-0.1.0.tar.gz
  • Upload date:
  • Size: 37.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.19

File hashes

Hashes for ojogu_gitai-0.1.0.tar.gz
Algorithm Hash digest
SHA256 0807ae53a671cc3c88e345f9f9ebcc5031cf9317be7a97064d12aee5fa950743
MD5 5a45e2e32d727c357f623efe9ad8dc8e
BLAKE2b-256 af2f6426ca1ed751d3c16a9720f76a04b18adbf6c85358eee7ebfecdc14dca7c

See more details on using hashes here.

File details

Details for the file ojogu_gitai-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: ojogu_gitai-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 41.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.19

File hashes

Hashes for ojogu_gitai-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 afee105ed7518429b70d6d0e16cefbc3b52932fcbb4d883d141f7cb264973add
MD5 6177e3f35bc9fa1a9f05ddcef9ca4efd
BLAKE2b-256 2c0345e8846e297743c71df3dd0a0155bbb2a3ade1adc334fcf1776348d67c49

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page