Automatically generate and suggest context-aware Git commit messages using OpenAI's GPT. This repository provides an easy-to-integrate solution to streamline your commit process and enhance commit message quality.
- Python 3
- OpenAI API key
- Clone this repository:
git clone https://github.com/your-username/gpt-commit-message-helper.git
cd gpt-commit-message-helper- Install the required Python packages:
pip install openai- Set your OpenAI API key as an environment variable:
export OPENAI_API_KEY=your_api_key_here-
Copy the
commit_with_suggestion.shscript to your target Git repository's root directory. -
Make the script executable:
chmod +x commit_with_suggestion.sh- Create a Git alias to run the script. Run the following command in your terminal:
git config --global alias.scommit '!sh ./commit_with_suggestion.sh'Instead of using git commit, use git scommit in your repository. This command will run the custom script, which will prompt you for the commit message with the GPT-generated suggestion. You can press ENTER to use the suggested commit message or type a custom one and press ENTER.
Example:
git add .
git scommitYou can customize the behavior of the script using the following environment variables:
GPT_COMMIT_MESSAGE_MODEL: The OpenAI language model to use for generating commit messages. The default value istext-davinci-002.GPT_COMMIT_MESSAGE_MAX_TOKENS: The maximum number of tokens to generate in the commit message. The default value is60.GPT_COMMIT_MESSAGE_TEMPERATURE: The sampling temperature to use when generating the commit message. The default value is0.7.GPT_COMMIT_MESSAGE_STOP: A string or list of strings to use as stop words when generating the commit message. The default value isNone.
This project is licensed under the MIT License. See the LICENSE file for details.