Skip to content
/ gc Public

A CLI tool written in Go that streamlines the process of crafting conventional Git commit messages. It provides an interactive experience for building commits and features an experimental AI-assisted commit message generation based on your staged changes.

Notifications You must be signed in to change notification settings

Augists/gc

Repository files navigation

gc - Git Commit with AI Assistance

gc is a command-line interface (CLI) tool written in Go that streamlines the process of crafting conventional Git commit messages. It provides an interactive experience for building commits and features an experimental AI-assisted commit message generation based on your staged changes.

Why gc?

Existing tools like cz-cli (JavaScript) and koji (Rust) offer similar functionalities for conventional commits. However, gc was created to address specific pain points and introduce new capabilities:

  1. Consistent Configuration Path: Unlike some existing tools that might place configuration files in OS-specific directories (e.g., ~/Library/Application Support/ on macOS), gc strictly adheres to the XDG Base Directory Specification for Unix-like systems, placing its configuration at $HOME/.config/gc/config.yaml. This provides a more intuitive and unified experience for users managing their CLI tool configurations.

  2. Go Native: Written in Go, gc compiles to a single, statically linked binary, making it easy to distribute and run across various platforms without requiring a runtime like Node.js or Rust toolchains for end-users.

  3. AI-Assisted Commit Messages: gc integrates with large language models (LLMs) like Google's Gemini to intelligently generate commit messages based on your staged Git diff. This can significantly speed up the commit process and help maintain high-quality, descriptive commit messages.

  4. Git Hook Integration: gc can be easily installed as a prepare-commit-msg Git hook, enabling seamless AI-powered commit message suggestions directly within your standard git commit workflow.

Building gc

To build gc from source, you need the Go toolchain installed (version 1.21 or newer recommended).

  1. Clone the repository:

    git clone https://github.com/Augists/gc.git
    cd gc
  2. Resolve Dependencies:

    go mod tidy
  3. Build the executable:

    go build -o gc

    This command will create an executable file named gc in the current directory.

Usage

Configuration

gc automatically creates a default configuration file at $HOME/.config/gc/config.yaml (or the appropriate OS-specific config directory on Windows) if one doesn't exist. You can customize the behavior, including LLM integration settings, in this file.

For a complete reference of all configurable options, see config.example.yaml in the project root.

To get started, copy the example configuration (run from the gc project root):

# For Unix-like systems (Linux, macOS):
cp config.example.yaml ~/.config/gc/config.yaml

# For Windows (adjust the path to your user config directory):
# copy config.example.yaml "%APPDATA%\gc\config.yaml"

Setting API Key via Environment Variable: For security, it's recommended to set your LLM API key as an environment variable (e.g., GEMINI_API_KEY) rather than directly in the config file:

export GEMINI_API_KEY="YOUR_GEMINI_API_KEY"

Interactive Commit

To use gc in interactive mode, simply run it in your Git repository:

./gc

This will guide you through prompts to construct a conventional commit message.

Use -v for INFO log and -vv for DEBUG log.

AI-Assisted Commit

To generate a commit message using AI based on your staged changes:

./gc ai

Important: Ensure you have staged your changes (git add .) and enabled LLM in your config.yaml and provided your API key before using this command.

Installing Git Hook

To integrate gc directly into your git commit workflow by automatically suggesting AI-generated messages, install the prepare-commit-msg hook:

./gc install-hook

After installing, when you run git commit, gc will attempt to generate a message using AI and populate your commit message editor with it. You can then review and modify it before finalizing the commit.

About

A CLI tool written in Go that streamlines the process of crafting conventional Git commit messages. It provides an interactive experience for building commits and features an experimental AI-assisted commit message generation based on your staged changes.

Resources

Stars

Watchers

Forks

Languages