Skip to main content

Generate commit messages from git diffs using OpenAI models

Project description

Git Message Generator

Generate meaningful commit messages automatically from git diffs using OpenAI's language models.

Overview

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.

Features

  • 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

Installation

Prerequisites

  • Python 3.7 or higher
  • OpenAI API key

Install using pip

pip install git-message

Configuration

  1. 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'
  1. (Optional) Add it to your shell profile for persistence:
# Add to ~/.bashrc, ~/.zshrc, etc.
export OPENAI_API_KEY='your-api-key'

Usage

Basic Usage

Generate a commit message for your current changes:

git diff | git-message

Using with Staged Changes

Generate a message for staged changes:

git diff --staged | git-message

Specify a Different Model

git diff | git-message --model gpt-4
# or
git diff | git-message -m gpt-4

List Available Models

git-message --list-models
# or
git-message -l

Git Alias Setup (Optional)

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

Command-Line Options

--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

Examples

Example 1: Basic Commit Message Generation

$ git diff | git-message
feat: Add user authentication middleware with JWT support

Example 2: Using a Different Model

$ git diff | git-message --model gpt-4
fix: Resolve race condition in database connection pool

Example 3: Complete Git Workflow

# 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

Contributing

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.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

Development Setup

# 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 .

License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details.

Acknowledgments

  • OpenAI for providing the API
  • The Python community for the excellent tools and libraries

Support

If you encounter any problems or have suggestions, please file an issue on the GitHub issue tracker.

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

git_message-0.1.0.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

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

git_message-0.1.0-py3-none-any.whl (4.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: git_message-0.1.0.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.6

File hashes

Hashes for git_message-0.1.0.tar.gz
Algorithm Hash digest
SHA256 923456b2f59223022f707f8280e10c14716b0018c7d8f23798406b3815158c20
MD5 1f38371ce7bf3d81771946f704f8c420
BLAKE2b-256 10c67a62e326a8cd42eecaf247d34a2cec10b79f159a9a0869b13690e28959ed

See more details on using hashes here.

File details

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

File metadata

  • Download URL: git_message-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.6

File hashes

Hashes for git_message-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a794783d131c6c42ca1b7a64c84d2295c51e65937e41d7dcf5623670b70f6678
MD5 4cdc2ff8fcb658ca388c7ba3ab6761fb
BLAKE2b-256 4a19dfde46fae90b4a94e3fc1499df078773e793916ed5b928c32d6c2e4dccd8

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