git-ai-commit
integrates AI-powered commit message generation into your Git workflow.
It leverages OpenAI's GPT-4 model to create concise and meaningful commit messages based on your staged or unstaged changes.
- AI-Generated Commit Messages: Automatically generate meaningful commit messages with a professional format.
- Customizable Commit Templates: Uses prefixes like
fix:
,refactor:
,docs:
, and ensures proper structure for both the headline and body. - Seamless Git Integration: Supports standard Git commit parameters like
-a
,-m
, and file-specific commits. - Editor Integration: Opens the Git editor with a pre-filled commit message for manual review and edits.
- Git: Ensure Git is installed and configured on your system.
- jq: Used for JSON processing.
- curl: Required for API requests.
- OpenAI API Key: Access to OpenAI's GPT-4 API.
- Clone the repository or copy the script.
- Save the script as
git-ai-commit
in a directory included in your$PATH
, such as/usr/local/bin/
. - Make the script executable:
chmod +x /usr/local/bin/git-ai-commit
- Ensure the required tools are installed:
sudo apt update sudo apt install git jq curl
-
Set your OpenAI API key:
git-ai-commit --set-chatgpt-key YOUR_API_KEY
This stores the API key in a
.env
file within the home directory of the current user. -
Verify the setup by running:
git-ai-commit --set-chatgpt-key <key>
git-ai-commit
supports standard Git commit options. Examples:
-
Stage all changes and generate a commit message:
git-ai-commit -a
-
Commit specific files with a generated commit message:
git-ai-commit file1.txt file2.txt
-
Commit with a custom message:
git-ai-commit -m "fix: updated README"
-
Generate a commit message but review and edit it in the editor:
git-ai-commit -a
The script will:
- Analyze your changes.
- Generate a commit message with a formatted headline and body.
- Open your editor with the pre-filled commit message.
fix: correct typo in README
This fixes a small typo in the installation section of the README file. It ensures that the instructions are clear and accurate for users setting up the tool.
If you encounter errors:
- Ensure the API key is correctly set and valid.
- Verify that your changes are staged or unstaged but present.
- Check for missing dependencies like
jq
orcurl
.
To remove git-ai-commit
, simply delete the script:
sudo rm /usr/local/bin/git-ai-commit
Also, remove the .env
file if it exists:
rm $HOME/.git-ai-commit.env
Feel free to submit issues or contribute to this project by opening a pull request.
This project is licensed under the MIT License. See the LICENSE file for details.