gcommit
is a command-line tool that leverages Google Cloud's AI models (specifically Gemini) to generate concise, well-formatted Git commit messages that adhere to Conventional Commits standards. It automates the creation of commit messages based on your staged changes.
-
Stage your changes: In your Git repository, add the files you want to include in the commit:
git add . # or git add <specific_files>
-
Run
gcommit
: Make sure you have installed and configuredgcommit
.gcommit
-
Confirm the message:
gcommit
will display the generated commit message and ask for your confirmation.β¨ Generated commit message: feat: PROJ-123 implement user authentication flow Use this commit message? [Y/n]:
Press
Y
(or Enter) to proceed with the commit, orn
to cancel. -
Forward arguments to
git commit
: You can pass arguments directly togit commit
aftergcommit
. For example, to sign a commit with GPG:gcommit -S
Or to add a longer description (opening the editor):
gcommit -v
- β¨ AI-Generated Commit Messages: Uses Google Cloud's Gemini models to create intelligent commit messages.
- π·οΈ Ticket ID Extraction: Automatically extracts ticket IDs (e.g.,
PROJ-123
) from the branch name and prepends them to the message. - π§ Context-Aware: Considers recent commit history and the files being modified.
- convention Conventional Commits: Generates messages that follow the Conventional Commits standard.
- π Concise and Formatted: Produces single-line messages, under 72 characters, in the imperative mood.
- π§ Configurable: Set your Google Cloud project, region, and model ID via environment variables.
- π¬ Interactive Confirmation: Asks for your approval before committing.
- passthrough Argument Forwarding: Allows you to forward additional arguments to the
git commit
command (e.g.,gcommit -S
to sign the commit). - π Debug Mode: Includes a
--debug
mode to inspect the prompt sent to the AI and its response.
Before installing gcommit
, ensure you have:
- Git: Installed and configured.
- jq: Installed (e.g.,
sudo apt install jq
orbrew install jq
). - Google Cloud SDK (
gcloud
): Installed and configured. You must be authenticated (gcloud auth login
) and have a default project configured (gcloud config set project YOUR_PROJECT_ID
). - Google Cloud Project:
- The Vertex AI API must be enabled.
- Billing must be configured for the project.
-
Clone the repository (if you haven't already):
git clone <YOUR_REPOSITORY_URL> cd <REPOSITORY_FOLDER_NAME> # e.g., cd gcommit
-
Run the installation script:
bash install.sh
This script will copy
gcommit
to~/.local/bin
and make it executable. Follow the instructions provided by the script if~/.local/bin
is not in yourPATH
.
gcommit
uses the following environment variables:
GGIT_PROJECT
: (Required) Your Google Cloud project ID.GGIT_LOCATION
: (Optional) The region for AI API calls. Default:europe-west8
.GGIT_MODEL_ID
: (Optional) The Gemini model ID to use. Default:gemini-2.0-flash-001
.
Add these variables to your shell's configuration file (e.g., ~/.bashrc
, ~/.zshrc
):
export GGIT_PROJECT="YOUR_GCP_PROJECT_ID"
# export GGIT_LOCATION="your-region" # Optional
# export GGIT_MODEL_ID="your-gemini-model" # Optional