Generate meaningful commit messages automatically from git diffs using OpenAI's language models.
Git Message Generator is a command-line tool that analyzes your git diffs and generates descriptive commit messages using OpenAI's language models. It helps developers create more meaningful and consistent commit messages with minimal effort.
- Generate commit messages automatically from git diffs
- Support for multiple OpenAI models (GPT-4, GPT-3.5, etc.)
- Easy integration with git workflow
- Command-line interface with helpful options
- List available OpenAI models
- Python 3.7 or higher
- OpenAI API key
pip install git-message
- Set your OpenAI API key as an environment variable:
# Linux/macOS
export OPENAI_API_KEY='your-api-key'
# Windows (CMD)
set OPENAI_API_KEY=your-api-key
# Windows (PowerShell)
$env:OPENAI_API_KEY='your-api-key'
- (Optional) Add it to your shell profile for persistence:
# Add to ~/.bashrc, ~/.zshrc, etc.
export OPENAI_API_KEY='your-api-key'
Generate a commit message for your current changes:
git diff | git-message
Generate a message for staged changes:
git diff --staged | git-message
git diff | git-message --model gpt-4
# or
git diff | git-message -m gpt-4
git-message --list-models
# or
git-message -l
Add this to your git config to create a shortcut:
git config --global alias.generate-msg '!git diff --staged | git-message'
Then use:
git generate-msg
--model, -m Specify the OpenAI model to use (default: gpt-4o-mini)
--list-models, -l List all available OpenAI models
--help, -h Show help message
$ git diff | git-message
feat: Add user authentication middleware with JWT support
$ git diff | git-message --model gpt-4
fix: Resolve race condition in database connection pool
# Stage your changes
git add .
# Generate commit message
git diff --staged | git-message > commit-msg.txt
# Review and edit if needed
vim commit-msg.txt
# Commit with the generated message
git commit -F commit-msg.txt
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature
) - Commit your changes (
git commit -m 'Add some AmazingFeature'
) - Push to the branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
# Clone the repository
git clone https://github.com/yourusername/git-message.git
cd git-message
# Create and activate virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install in editable mode
pip install -e .
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
- OpenAI for providing the API
- The Python community for the excellent tools and libraries
If you encounter any problems or have suggestions, please file an issue on the GitHub issue tracker.