A command-line tool that uses Google Gemini AI to automatically generate commit messages based on your staged changes. It follows the Conventional Commits specification.
- Analyzes
git diffoutput. - Generates concise and meaningful commit messages using Google Gemini.
- Formats messages according to the Conventional Commits standard (e.g.,
feat:,fix:,docs:, etc.). - Adds all unstaged files and commits them with the generated message.
-
Clone the repository (or download the source code):
git clone https://github.com/JPLeopoldino/aicommit-cli.git cd aicommit-cli -
Install the package: It's recommended to install it in a virtual environment.
python -m venv venv source venv/bin/activate # On Windows use `venv\Scripts\activate` pip install .
Alternatively, for development:
pip install -e .
-
Get a Gemini API Key: Obtain an API key from Google AI Studio.
-
Set up Environment Variable: Create a
.envfile in the root of your project (the one you want to commit in, not theaicommit-clidirectory unless you are developing the tool itself):GEMINI_API_KEY=YOUR_API_KEY_HEREReplace
YOUR_API_KEY_HEREwith your actual Gemini API key.aicommit-cliwill automatically load this key. Alternatively, you can set theGEMINI_API_KEYenvironment variable globally in your system.
Navigate to your Git repository directory in the terminal and simply run:
aicommitOptions:
-vor--verbose: Show detailed messages during execution (e.g., diff checking, API call, staging, committing).-l <lang>or--lang <lang>: Specify the language for the generated commit message. Supported languages:en(English, default),pt(Portuguese).-m <model_name>or--model <model_name>: Specify the Gemini model to use. Defaults togemini-1.5-flash. Check Google AI documentation for available models.-bor--new-branch: Generate a branch name using AI, create and checkout the new branch before committing.-ior--interactive: Prompt for confirmation before using the generated branch name or commit message. Allows regenerating if the suggestion is not suitable.
Examples:
- Generate a commit message in English using the default model:
aicommit
- Generate a commit message in Portuguese, show verbose output, and use a specific model:
aicommit -l pt -v -m gemini-pro
The tool will:
- Check for staged changes (
git diff --staged). If found, proceed to step 3 with these changes. - If no staged changes, check for unstaged changes (
git diff). If found, proceed to step 3 with these changes. - Send the diff to the Gemini API (using the specified model) to generate a commit message in the specified language.
- Display the generated message (and other steps if
--verboseis used). - If unstaged changes were used, stage all changes (
git add .). - Commit the changes with the generated message (
git commit -m "message").
Contributions are welcome! Please feel free to submit a pull request or open an issue.
This project is licensed under the MIT License - see the LICENSE file for details (Note: LICENSE file needs to be created if desired).