AI git commit message
A Ruby gem that automatically generates concise and meaningful git commit messages using AI models via Ollama or any OpenAI-compatible API.
Installation
Install the gem using:
gem install ai-commit-message
Or add it to your Gemfile:
gem 'ai-commit-message'
And then run:
bundle install
Requirements
- Ruby 3.0 or newer
- Git repository
- Ollama model running locally or other OpenAI-compatible API endpoint
Usage
Basic Usage
Generate a commit message for your staged changes:
ai-commit-message commit
This will:
- Analyze your staged changes (
git diff --cached) - Review your recent commit history for style consistency
- Consider your current branch name
- Generate an appropriate commit message
Configuration
You can configure the gem using the built-in configuration command:
ai-commit-message config
This interactive prompt allows you to set:
- API URL: The endpoint for your AI model (defaults to
http://localhost:11434/api/generate) - Model name: The AI model to use (defaults to
qwen2.5-coder:7b, which I personally recommend)
Command Line Options
Override configuration settings directly:
ai-commit-message commit --url=http://your-api-endpoint --model=your-model-name
How It Works
The gem:
- Collects your staged changes using
git diff --cached - Retrieves your recent commit history for context
- Identifies your current branch name
- Sends this information to the specified AI model
- Returns a concise, contextual commit message (limited to 250 characters)
Configuration File
The gem stores your configuration in ~/.ai-commit-message.conf. You can manually edit this file if needed. Example:
url=http://localhost:11434/api/generate
model=qwen2.5-coder:7b
Models
The default configuration uses Ollama with the qwen2.5-coder:7b model, but you can use any model available through your API endpoint.
Recommended Models
- qwen2.5-coder:7b: Good balance of quality and speed (default)
- llama3:8b: Excellent for general commit messages
- codellama:7b: Specialized for code-related commits
Contributing
- Fork the repository
- Create your feature branch:
git checkout -b my-new-feature - Install dependencies:
bundle install - Make your changes and add tests if applicable
- Commit your changes:
git commit -m 'Add some feature' - Push to the branch:
git push origin my-new-feature - Submit a pull request
License
This gem is available as open source free to use/alter without restrictions.