co - AI-Powered Git Commit Message Generator

co is a command-line tool that uses OpenAI's GPT-4o to generate meaningful, well-formatted git commit messages based on your staged changes.
Features
- 🤖 Generates contextual commit messages based on your staged git changes
- 🔑 Securely manages your OpenAI API key
- ✏️ Interactive editor to review and modify suggested commit messages
- 📋 Supports multiple commit message formats:
- Conventional Commits
- Gitmoji (Unicode or shortcode format)
- Simple format
Prerequisites
- Git installed and configured
- An OpenAI API key (with access to GPT-4o)
Installation
You'll need Go (Golang) installed so that you can run the following command to install co:
go install github.com/hamzabow/co@latest
Once installed, you can use co in any git repository. See the Usage section below for instructions.
Setup
You can provide your OpenAI API key in one of two ways:
-
Set the OPENAI_API_KEY environment variable:
export OPENAI_API_KEY="your-api-key-here"
-
Enter it when prompted on first use. The tool will ask for your API key if not found in environment variables.
Usage
-
Stage your changes with git:
git add .
-
Run the commit message generator:
co
-
Review the generated message, edit if needed, and:
- Press
Ctrl+Enter to commit with the message
- Press
Ctrl+C to cancel
How It Works
- The tool retrieves the diff of your staged changes using
git diff --staged
- It sends this diff to OpenAI's API with a carefully crafted prompt
- The AI generates a commit message following the specified format
- You get to review and edit the message before committing
- After confirmation, the tool executes
git commit -m "your message"
Configuration
The tool currently uses the Conventional Commits format by default. You can modify the format by editing the internal/genmessage/genmessage.go file to use one of the other prompt templates defined in internal/prompts/prompts.go.
Contributing
Contributions are welcome! Feel free to open issues or submit pull requests for new features, improvements, or bug fixes.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgments
- Built with Bubble Tea for the terminal UI
- Uses the OpenAI API for generating commit messages