This script automates the generation of git commit messages using the OpenAI API.
It captures the staged changes (git diff --staged
), uses a predefined template, and optionally incorporates the name of a subdirectory as part of the commit message.
The final commit message is then copied to the clipboard for easy use.
Before using this script, ensure that you have the OPENAI_API_TOKEN
environment variable set in your session. This token is required for the script to authenticate with the OpenAI API and generate commit messages. You can set this variable in your shell's configuration file (e.g., .bashrc
, .zshrc
) like so:
export OPENAI_API_TOKEN='your_openai_api_token_here'
Replace your_openai_api_token_here
with your actual OpenAI API token.
To install this script globally using yarn
, follow these steps:
- Clone the repository to your local machine.
- Navigate to the directory containing the script.
- Run the following command to install the script globally:
yarn global add "file:$PWD"
After installation, you can run the script from any git repository by executing:
ggcm
or
generate-git-commit-message
Ensure you have staged changes (git add
) before running the script. The script will generate a commit message based on your staged changes and the template provided, then copy this message to your clipboard. You can then use git commit
and paste the message to commit your changes.
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.