GitAI is a small Bash script that generates commit messages using an AI model. The script inspects your staged changes and asks the configured API to suggest a commit title and description following the Conventional Commits style.
- Works with your existing Git workflow.
- Supports multiple providers: AvalAI, OpenRouter, Cloudflare Workers AI, and Google AI Studio (Gemini API).
- Warns about unstaged changes before committing.
- Trims very large diffs to avoid sending excessively long requests.
- Interactive prompts let you review and accept the generated message.
Clone this repository and place the gitai script somewhere in your PATH or run it directly from the repository root:
# Clone the repository
git clone <repository url>
cd gitai
# Optional: copy the script somewhere in your PATH
cp gitai /usr/local/bin/GitAI needs API credentials. You can either use a shared key (GITAI_API_KEY) or provider-specific keys, and you can set them as environment variables or in a .gitai file next to the script.
Example .gitai file:
export GITAI_PROVIDER="google,openrouter,cloudflare,avalapis"
export GITAI_GOOGLE_API_KEY="your-google-key"
export GITAI_OPENROUTER_API_KEY="your-openrouter-key"
export GITAI_CLOUDFLARE_API_KEY="your-cloudflare-key"
export GITAI_AVALAPIS_API_KEY="your-avalapis-key"
export GITAI_CLOUDFLARE_ACCOUNT_ID="your-cloudflare-account-id"Set GITAI_PROVIDER to one provider or a comma-separated fallback chain:
avalapis(default)openroutercloudflaregoogle
Examples:
GITAI_PROVIDER="google,openrouter,cloudflare,avalapis"GITAI_PROVIDER="openrouter"
Additional provider-specific variables:
openrouter- Optional:
GITAI_MODEL(defaultopenai/gpt-4o-mini)
- Optional:
cloudflare- Required unless
GITAI_API_BASEis set:GITAI_CLOUDFLARE_ACCOUNT_ID - Optional:
GITAI_MODEL(default@cf/meta/llama-3.3-70b-instruct-fp8-fast)
- Required unless
google- Optional:
GITAI_MODEL(defaultgemini-2.0-flash)
- Optional:
Global optional variables:
GITAI_API_BASE: Override endpoint URL (advanced use)GITAI_MAX_DIFF_LENGTH: Max diff chars sent to model (default12000)GITAI_MODEL: Shared default model override
Per-provider API keys (recommended for fallback chains):
GITAI_AVALAPIS_API_KEYGITAI_OPENROUTER_API_KEYGITAI_CLOUDFLARE_API_KEYGITAI_GOOGLE_API_KEY
Per-provider model overrides (optional):
GITAI_AVALAPIS_MODELGITAI_OPENROUTER_MODELGITAI_CLOUDFLARE_MODELGITAI_GOOGLE_MODEL
Stage your changes and run the script:
git add file.txt
./gitaiGitAI will print git status, send your diff to the configured provider, and show the suggested commit message. You can then choose whether to commit and optionally push.
A complete example is available in examples/basic_usage.sh.
Contributions are welcome! Please open issues or pull requests on GitHub.
This project is licensed under the MIT License. See LICENSE for details.