Skip to main content

AI-Powered Git Commit Message Generator

Project description

   # Commit-Gen - AI-Powered Git Commit Message Generator

PyPI version Python 3.8+

Generate intelligent commit messages using AI with support for multiple providers including OpenRouter, Ollama, Google Gemini, and Mistral AI.

๐Ÿš€ Quick Start

Installation

pip install commit-gen

First Time Setup

# Interactive setup wizard (recommended)
commit-gen --setup

# Or manual setup
commit-gen --set-provider openrouter
commit-gen --set-api-key YOUR_API_KEY

Basic Usage

# Interactive file selection and commit
commit-gen

# Commit specific files
commit-gen --files src/main.py tests/test_main.py

# Commit all files
commit-gen --all

# Commit and push
commit-gen --push

๐Ÿ”‘ API Key Setup

OpenRouter

Step 1: Create Account

  1. Visit OpenRouter
  2. Click "Sign Up" and create an account
  3. Verify your email address

Step 2: Get API Key

  1. Go to OpenRouter API Keys
  2. Click "Create Key"
  3. Give your key a name (e.g., "commit-gen")
  4. Copy the generated API key

Step 3: Configure

commit-gen --set-provider openrouter
commit-gen --set-api-key YOUR_OPENROUTER_API_KEY

๐Ÿ’ก Tips:

  • OpenRouter provides access to multiple AI models
  • Free tier available with limited usage
  • Supports models like GPT-4, Claude, and others

Google Gemini

Step 1: Create Google Cloud Project

  1. Visit Google Cloud Console
  2. Create a new project or select existing one
  3. Enable the Gemini API

Step 2: Enable Gemini API

  1. Go to Google AI Studio
  2. Click "Get API key"
  3. Create a new API key
  4. Copy the generated key

Step 3: Configure

commit-gen --set-provider gemini
commit-gen --set-api-key YOUR_GEMINI_API_KEY

๐Ÿ’ก Tips:

  • Free tier: 15 requests per minute
  • Supports models: gemini-2.5-flash, gemini-2.5-pro
  • Requires Google Cloud account

Mistral AI

Step 1: Create Account

  1. Visit Mistral AI
  2. Click "Sign Up" and create an account
  3. Verify your email address

Step 2: Get API Key

  1. Go to Mistral AI Console
  2. Click "Create new API key"
  3. Give your key a name (e.g., "commit-gen")
  4. Copy the generated API key

Step 3: Configure

commit-gen --set-provider mistral
commit-gen --set-api-key YOUR_MISTRAL_API_KEY

๐Ÿ’ก Tips:

  • Free tier: 20 requests per minute
  • Supports models: mistral-large-latest, mistral-medium-latest
  • High-quality reasoning capabilities

Ollama (Local - No API Key Required)

Step 1: Install Ollama

# macOS/Linux
curl -fsSL https://ollama.ai/install.sh | sh

# Windows
# Download from https://ollama.ai/download

Step 2: Start Ollama

ollama serve

Step 3: Pull Model

ollama pull qwen2.5-coder:7b

Step 4: Configure

commit-gen --set-provider ollama
# No API key needed for local Ollama

๐Ÿ’ก Tips:

  • Runs locally on your machine
  • No internet required after model download
  • Free to use
  • Supports many open-source models

Custom Provider

Step 1: Get API Key

  1. Obtain API key from your custom provider
  2. Note the base URL for the provider

Step 2: Configure

commit-gen --set-provider custom
commit-gen --set-api-key YOUR_CUSTOM_API_KEY
commit-gen --set-base-url https://your-provider.com/api/v1

โœจ Key Features

  • ๐Ÿค– AI-Powered: Generate commit messages using advanced AI models
  • ๐Ÿ“ Interactive File Selection: Choose which files to commit with arrow key navigation
  • ๐Ÿ”ง Multiple AI Providers: Support for OpenRouter, Ollama, Google Gemini, Mistral AI
  • โš™๏ธ Easy Configuration: Interactive setup wizard and simple CLI commands
  • ๐Ÿ“ Smart Review: Edit and confirm commit messages before committing
  • ๐Ÿš€ Auto Push: Optional automatic push to remote repository

๐Ÿ› ๏ธ Supported AI Providers

Provider Type Default Model API Key Required Free Tier
OpenRouter Cloud moonshotai/kimi-k2:free โœ… โœ…
Ollama Local qwen2.5-coder:7b โŒ โœ…
Google Gemini Cloud gemini-2.5-flash โœ… โœ…
Mistral AI Cloud mistral-large-2411 โœ… โœ…
Custom Any Configurable โœ… Varies

๐Ÿ“– Usage Examples

Interactive File Selection

commit-gen

Shows an interactive interface where you can:

  • Navigate files with โ†‘/โ†“ arrow keys
  • Toggle selection with SPACE
  • See file status (modified, added, untracked)

File Selection Interface

When you run commit-gen without arguments, you'll see an interactive interface with arrow key navigation:

๐Ÿ“ Files to commit:
============================================================
Use โ†‘/โ†“ to navigate, SPACE to toggle, ENTER to confirm
a=select all, n=select none, s=skip (stage all), q=quit

๐Ÿ“‚ CODE:
โ†’ [ ] commit_gen/cli.py (modified, 18KB)
  [x] demo_file2.py (added, 13B) โœ…
  [ ] README.md (modified, 9KB)
  [ ] arrow_config.json (untracked, 12B)

Selected: 1/4 files

Navigation Controls:

  • โ†‘/โ†“ Arrow Keys: Navigate through files
  • SPACE: Toggle file selection (check/uncheck)
  • ENTER: Confirm selection and proceed
  • a: Select all files
  • n: Select none (use only already staged files)
  • s: Skip selection (stage all files)
  • q: Quit without committing

Visual Indicators:

  • โ†’: Current cursor position
  • [x]: Selected file
  • [ ]: Unselected file
  • โœ…: Already staged file
  • Selected: X/Y files: Shows selection count

Features:

  • Status indicators: Shows if files are modified, added, or untracked
  • Size information: Displays file sizes
  • Staged markers: Shows which files are already staged
  • Real-time selection: See selection count update as you navigate
  • Keyboard navigation: Intuitive arrow key and spacebar controls

Commit Confirmation

After selecting files, commit-gen will:

  1. Generate AI commit message
  2. Show commit message for review
  3. Allow editing (with external editor or simple input)
  4. Confirm before committing

Commit Review Interface:

๐Ÿค– Generating commit message...

๐Ÿ“ Edit commit message:
============================================================
Current commit message:
------------------------------
feat: add interactive file selection with arrow keys

- Implement arrow key navigation for file selection
- Add spacebar toggle for file selection
- Improve UX with visual indicators and real-time feedback
------------------------------

Options:
1. Edit message
2. Use as-is
3. Cancel

Commit Confirmation:

๐Ÿ” Commit Review:
============================================================
Commit message:
------------------------------
feat: add interactive file selection with arrow keys

- Implement arrow key navigation for file selection
- Add spacebar toggle for file selection
- Improve UX with visual indicators and real-time feedback
------------------------------

Options:
1. โœ… Yes, commit
2. ๐Ÿš€ Yes, commit and push
3. โŒ No, go back to editing
4. ๐Ÿšช Cancel

Confirmation Options:

  • Yes, commit: Commit only
  • Yes, commit and push: Commit and push to remote
  • No, go back to editing: Return to edit commit message
  • Cancel: Exit without committing

Editing Options:

  • External Editor: Uses $EDITOR (default: nano)
  • Simple Input: Fallback if editor not available
  • Validation: Ensures commit message is not empty

Quick Commits

# Commit specific files
commit-gen --files src/main.py tests/test_main.py

# Commit all modified files
commit-gen --all

# Commit and push automatically
commit-gen --push

Provider Configuration

# Set provider
commit-gen --set-provider gemini

# Set API key
commit-gen --set-api-key YOUR_API_KEY

# Set custom model
commit-gen --set-model gemini-2.5-pro

# View current config
commit-gen --config

๐Ÿ”ง Configuration

Interactive Setup (Recommended)

commit-gen --setup

Guides you through:

  • Provider selection
  • API key configuration
  • Model selection
  • Connection testing

Manual Configuration

# Show available providers
commit-gen --providers

# Configure OpenRouter
commit-gen --set-provider openrouter
commit-gen --set-api-key YOUR_OPENROUTER_KEY

# Configure Ollama (local)
commit-gen --set-provider ollama
# No API key needed for Ollama

# Configure Google Gemini
commit-gen --set-provider gemini
commit-gen --set-api-key YOUR_GEMINI_KEY

# Configure Mistral AI
commit-gen --set-provider mistral
commit-gen --set-api-key YOUR_MISTRAL_KEY

๐ŸŽฏ Advanced Features

Custom Prompts

# Inline prompt
commit-gen --prompt "Generate a conventional commit message: {changes}"

# Load prompt from file
commit-gen --prompt-file my_prompt.txt

# Save current prompt to file
commit-gen --save-prompt-file my_prompt.txt

Example prompt file (my_prompt.txt):

You are an expert developer. Generate a clear, concise commit message based on the following changes:

{changes}

Requirements:
- Use conventional commit format (type: description)
- Keep it under 50 characters for the first line
- Add detailed description if needed
- Focus on what changed and why
- Use present tense ("add" not "added")
- Be specific but concise

Examples:
- feat: add user authentication system
- fix: resolve memory leak in data processing
- docs: update API documentation
- refactor: simplify database query logic

Changelog Generation

commit-gen --changelog
commit-gen --changelog --compare-branch develop

Debug Mode

commit-gen --debug

Troubleshooting

Issue: Command not found after installation

If commit-gen command is not found after installation:

  1. Check if symlink exists:

    ls -la /usr/local/bin/commit-gen
    
  2. If symlink is broken, recreate it:

    sudo ln -s /path/to/your/project/commit-gen.py /usr/local/bin/commit-gen
    
  3. For pip installation, check PATH:

    which commit-gen
    echo $PATH
    

Issue: Configuration files not cleaned up

If configuration files remain after uninstallation:

rm -rf ~/.config/git-commit-ai/

Issue: API Key Authentication Failed

Common Solutions:

  1. Check API Key Format:

    • Ensure no extra spaces or characters
    • Copy the entire key from provider dashboard
  2. Verify Provider Configuration:

    commit-gen --config
    
  3. Test with Different Model:

    commit-gen --set-model gpt-4o-mini  # For OpenRouter
    commit-gen --set-model gemini-2.5-flash  # For Gemini
    
  4. Check API Key Permissions:

    • Ensure key has proper permissions
    • Check if key is active in provider dashboard

Issue: Rate Limiting

Solutions:

  • OpenRouter: Upgrade to paid plan for higher limits
  • Gemini: Wait for rate limit reset (usually 1 minute)
  • Mistral: Check usage in Mistral console
  • Ollama: No rate limits (local usage)

๐Ÿ“‹ Requirements

  • Python: 3.8 or higher
  • Git: Working git repository
  • AI Provider: At least one AI provider configured

๐Ÿ™ Acknowledgments

  • Powered by various AI providers
  • Inspired by the need for better commit messages

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

commit_gen_cli_test-1.1.0.tar.gz (38.2 kB view details)

Uploaded Source

Built Distribution

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

commit_gen_cli_test-1.1.0-py3-none-any.whl (31.2 kB view details)

Uploaded Python 3

File details

Details for the file commit_gen_cli_test-1.1.0.tar.gz.

File metadata

  • Download URL: commit_gen_cli_test-1.1.0.tar.gz
  • Upload date:
  • Size: 38.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.9

File hashes

Hashes for commit_gen_cli_test-1.1.0.tar.gz
Algorithm Hash digest
SHA256 804b808b2b37e112ca0d4a2d8868d591e63904b109876a14f3d1eb5867264dc9
MD5 6f05e274fb526c3d67b9bda08d85272b
BLAKE2b-256 ee76653c5da3358d6f14bfe886192dcea0d80585da38853edc2eadcfe2435515

See more details on using hashes here.

File details

Details for the file commit_gen_cli_test-1.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for commit_gen_cli_test-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f78c82edf7aa8ed374fa4e647014ea59691f11b3ef2c8b993a79ad81c8a9ede8
MD5 31fa8082286150bbd950ccd52c3057ef
BLAKE2b-256 f884f4c7e3f4d738da0a3a5df743842ddffc1dbafa07ba1fef7eb6d2ee4fd05f

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