A simple yet powerful tool that uses the Google Gemini AI to automatically generate descriptive and conventional commit messages from your staged changes.
Tired of spending time thinking about the perfect commit message? This project automates that process. It reads your staged code differences (git diff), sends them to the Gemini API with a carefully crafted prompt, and returns a commit message that follows the Conventional Commits specification.
The workflow is handled by a simple shell script (gcommit.sh) that makes the process seamless right from your terminal.
- AI-Powered Messages: Leverages Google Gemini for high-quality, context-aware commit messages.
- Conventional Commits: Enforces a structured commit history, making it easier to understand changes and automate releases.
- Interactive Workflow: The script allows you to accept, edit, or reject the generated message before committing.
- Easy Setup: Requires minimal configuration to get started.
Follow these steps to set up the project locally.
- Git installed on your system.
- Python 3.6+ and Pip.
- A Google Gemini API Key. You can get one for free at Google AI Studio.
-
Clone the repository:
git clone [https://github.com/your-username/PatroAutoCommit.git](https://github.com/your-username/PatroAutoCommit.git) cd PatroAutoCommit -
Install Python dependencies:
pip install google-generativeai python-dotenv pyperclip
-
Set up your environment variables: This project requires a Gemini API key. We use a
.env.examplefile to show you which variables are needed.First, copy the example file to a new file named
.env:# For Linux/macOS cp .env.example .env # For Windows (Command Prompt) # copy .env.example .env
Next, open the new
.envfile and add your personal Gemini API key:GEMINI_API_KEY="PASTE_YOUR_API_KEY_HERE"This
.envfile is already listed in.gitignore, so your key will remain private. -
Make the script executable:
chmod +x gcommit.sh
Using the tool is straightforward:
-
Stage your changes as you normally would:
git add . # or git add <file1> <file2>
-
Run the script:
./gcommit.sh
-
The script will generate a message and prompt you for action:
- Press
yto commit with the generated message. - Press
eto open your default text editor to edit the message before committing. - Press any other key to cancel the commit.
- Press
That's it! Your commit will be created with a clean, AI-generated message.
Distributed under the MIT License. See LICENSE for more information.
Luis Felipe Patrocinio - GitHub