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.
- 🤖 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
- Git installed and configured
- An OpenAI API key (with access to GPT-4o)
You'll need Go (Golang) installed so that you can run the following command to install co:
go install github.com/hamzabow/co@latestOnce installed, you can use co in any git repository. See the Usage section below for instructions.
You can provide your OpenAI API key in one of two ways:
-
Set the
OPENAI_API_KEYenvironment 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.
-
Stage your changes with git:
git add . -
Run the commit message generator:
co
-
Review the generated message, edit if needed, and:
- Press
Ctrl+Enterto commit with the message - Press
Ctrl+Cto cancel
- Press
- 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"
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.
Contributions are welcome! Feel free to open issues or submit pull requests for new features, improvements, or bug fixes.
This project is licensed under the MIT License - see the LICENSE file for details.
This project uses components and utilities from Bubble Tea for its terminal user interface.