A command-line tool that uses OpenAI's GPT-3.5 to automatically generate meaningful git commit messages based on your changes.
- Automatically generates conventional commit messages from your git diff
- Works with both staged and unstaged changes
- Interactive confirmation before committing
- Automatically stages all changes upon confirmation
- Clone this repository
- Build this binary:
go build -o smart-commit
- Move the binary to your path:
mv smart-commit ~/bin/
- Set your OpenAI API key as an environment variable:
export OPENAI_API_KEY='your-api-key-here'
To persist your API key, you can add it to your .zshrc
file:
echo "export OPENAI_API_KEY='your-api-key-here'" >> ~/.zshrc
Navigate to your git project:
cd your-project
Make some changes to your files
Run the tool:
smart-commit # Go version
I use an alias in my zsh config to make it easier to run:
echo 'alias sc="smart-commit"' >> ~/.zshrc
source ~/.zshrc
and run it with sc
The script will:
- Get the diff of your changes (staged or unstaged)
- Send it to OpenAI's API
- Generate a commit message
- Show you the proposed message
- Ask for confirmation before proceeding
- If confirmed, stage all changes and create the commit
- Requires all changes to be committed together (no partial commits)
- Requires manual API key setup
Contributions are welcome! Some potential areas for improvement:
- Add support for detailed commit messages with body and footer
- Add configuration options for commit message style
- Add support for partial commits
- Add rate limiting and token usage optimization
- Add support for different AI models or providers
This project is open-sourced under the MIT License - see the LICENSE file for details.