AI-powered commit message generator that analyzes your git diff and suggests meaningful commit messages.
The script will:
- Get the git diff of staged changes
- Send the diff to OpenAI API
- Generate a commit message
- Let you accept/reject/edit the suggested message
- Python 3.8+
- OpenAI API key
- Git installed and configured
Create a .env file with your OpenAI API key:
OPENAI_API_KEY=sk-your-api-key-hereThis key should start with sk- and can be generated in your OpenAI dashboard.
- Clone the repo
git clone https://github.com/klokie/git-smart- Install dependencies
pip install .- Set up environment variables
cp .env.example .env-
Add your OpenAI API key to
.env -
Show usage
git_smartGet commit message for staged changes:
git diff --staged | git_smartOr for all changes since last commit:
git diff HEAD | git_smartYou can also provide the diff text directly:
git_smart "diff --git a/file.txt b/file.txt ..."Make an alias in your .zshrc or .shrc:
alias gac="git diff --staged | git_smart"This project is open-sourced under the MIT License - see the LICENSE file for details.