A command-line tool that acts as a general-purpose AI assistant for your git workflow. It can automatically generate PR titles and descriptions, provide code reviews, generate commit messages, and more, streamlining your workflow.
This CLI tool connects to the GitHub (gh) CLI and a generative AI to perform two main functions:
-
GitHub Interaction (
ghsubcommand):- Detects the current repository you are in.
- Starts an interactive session, prompting for a pull request number.
- Fetches the code changes (diff) for the specified PR.
- Asks whether you want to generate PR details (title/description) or a code review.
- Sends the diff to a generative AI for analysis.
- Updates the pull request on GitHub with the AI-generated content or posts a review as a comment.
-
Commit Message Generation (
commitsubcommand):- Gets the staged diff from your local git repository.
- Sends the diff to a generative AI to generate a conventional commit message.
- Prompts for confirmation before committing the changes with the generated message.
Before you begin, ensure you have the following installed and configured:
- GitHub CLI: The tool used to interact with GitHub.
- Make sure you are authenticated by running
gh auth login.
- Make sure you are authenticated by running
- Google AI API: The API key used to interact with the AI.
This tool requires a Google AI API key to function. You must set the GOOGLE_AI_API_KEY environment variable for the application to work.
You can export the variable in your shell. Note that this is not the most secure method for long-term use.
export GOOGLE_AI_API_KEY="your-api-key-here"To make it persist between sessions, you can add this line to your shell's configuration file (e.g., ~/.zshrc, ~/.bashrc).
For better security, it is highly recommended to use a secret manager to handle your API key. This prevents storing secrets in plain text.
The application will automatically read the environment variable if it's provided by a secret manager's CLI.
Example with Bitwarden CLI:
# The `bw run` command injects the secret into the command's environment
bw run -- gitai ghExample with Doppler:
# The `doppler run` command works similarly
doppler run -- gitai commitUsing this wrapper pattern is the most secure way to provide credentials to the application.
We recommend using Nix and direnv for an easy and reproducible setup. This project provides a flake.nix and .envrc for seamless development environment configuration.
- Install Nix if you haven't already.
- Install direnv and hook it into your shell (see direnv docs for your shell).
After cloning the repository, run:
direnv allowThis will automatically set up the development environment using Nix, as defined in flake.nix and .envrc.
With the environment active, install the necessary packages using Bun:
bun installRun the build script to compile the application into a single executable file:
bun run buildThis will create a gitai executable in the project root.
To use the gitai command from anywhere, create a symbolic link from the compiled binary to a directory in your system's PATH. For example:
ln -s "$(pwd)/gitai" /usr/local/bin/gitaiNote: You might need to use
sudoto create the link in/usr/local/bindepending on your system's permissions. If a file already exists at that location, you may need to remove it first.
Once linked, you can run gitai from any directory.
Once installed, you can use the gitai command from within any local Git repository directory that has a GitHub remote.
Run the gh subcommand to start an interactive session for PR-related tasks.
gitai ghThe tool will then guide you through the process:
? Please enter the PR number: › 123
? What would you like to do?
❯ Generate title and description
Generate title only
Generate a review and post as a comment
Run the commit subcommand to generate a commit message for your staged changes.
gitai commitThe tool will analyze your staged changes, generate a message, and ask for confirmation before committing.
Generated commit message:
feat(cli): add commit message generation
- Adds a new `commit` subcommand to generate commit messages from staged changes.
- Implements a `GitClient` to interact with git.
- Updates the AI generator to create commit messages.
? Would you like to commit with this message? › yes
✅ Successfully committed changes!
For local development, you can run the tool directly from its source code without needing to build it after every change. This is the most efficient way to work when you are actively writing or testing code.
Simply use the gitai script, which is configured in package.json to execute the main script:
bun run gitaiAny changes you save to the source files will be reflected immediately when you run this command.
To see all available commands and options, use the --help flag.
gitai --helpYou can also get help for a specific subcommand:
gitai gh --helpgitai commit --helpTo create a new release:
npm run releaseThis script will:
- Check the latest git tag to determine the current version
- Prompt you to choose a version bump type (major, minor, or patch)
- Create and push a new git tag (e.g.,
v1.0.0) - Trigger the GitHub Actions release workflow
The release workflow will automatically:
- Build the binary with
bun run build - Create a GitHub release with the binary attached
- Generate release notes from recent commits
Users can then download the gitai binary directly from the GitHub releases page.