Tired of writing git commit messages? Let AI do it for you! ✨
commiat
is a simple CLI tool that:
- Optionally stages all changes (
git add .
) if you use the-a
or--add-all
flag. - Analyzes your staged git changes (
git diff --staged
). - Generates a commit message using an AI model via OpenRouter (defaults to Google Gemini Flash 1.5 ⚡) or a local Ollama instance (defaults to qwen2.5).
-
Supports custom commit message formats defined in a local
.commiat
file. - Prompts you to confirm ✅, adjust 📝, or cancel ❌ the commit.
- Optionally bypasses git commit hooks using the
-n
or--no-verify
flag.
npm install -g commiat
-
Clone the repository:
git clone https://github.com/javimosch/commiat.git cd commiat
-
Install dependencies:
npm install
-
Link the CLI:
This makes the
commiat
command available globally.npm link
commiat
uses two types of configuration:
This file stores settings that apply across all your projects, primarily your LLM provider choice, API keys, and default models. It uses the standard .env
format (KEY=VALUE).
-
Location:
~/.commiat/config
(created automatically if needed) -
Managed via:
commiat config
(for OpenRouter) andcommiat ollama
(for Ollama) commands. -
Key Settings:
-
OpenRouter:
-
COMMIAT_OPENROUTER_API_KEY
: Your OpenRouter API key (required if using OpenRouter). If not found here or in environment variables, you'll be prompted. -
COMMIAT_OPENROUTER_MODEL
: The default OpenRouter model ID (e.g.,google/gemini-flash-1.5
,anthropic/claude-3-haiku
). Defaults togoogle/gemini-flash-1.5
.
-
-
Ollama: (Managed via
commiat ollama
)-
COMMIAT_USE_OLLAMA
: Set totrue
to use Ollama instead of OpenRouter. Defaults tofalse
. -
COMMIAT_OLLAMA_BASE_URL
: The base URL for your running Ollama instance. Defaults tohttp://localhost:11434
. -
COMMIAT_OLLAMA_MODEL
: The Ollama model to use. Defaults tollama3
. -
COMMIAT_OLLAMA_FALLBACK_TO_OPENROUTER
: Set totrue
to automatically fall back to OpenRouter if the Ollama request fails (requires OpenRouter API key to be configured). Defaults tofalse
.
-
-
OpenRouter:
This optional file, placed in your project's root directory, allows you to define a custom commit message format for that specific project.
-
Location:
.commiat
in your project root. - Format: JSON
-
Structure Example:
{ "format": "{type}({scope}): {msg} [Ticket: {gitBranchNumber}]", "variables": { "scope": "Description of what 'scope' means in this project (e.g., component, module, feature name)" } }
-
format
(string, required): The template for your commit messages.- Use
{variableName}
for placeholders. -
{msg}
is special: The main commit message generated by the AI will replace this. -
System Variables: These are automatically handled by
commiat
:-
{gitBranch}
: The full current Git branch name (e.g.,feature/DATA-123-button
). -
{gitBranchNumber}
: The first sequence of digits found in the branch name (e.g.,123
fromfeature/DATA-123-button
). Returns empty string if no number is found. -
{type}
: The conventional commit type (e.g.,feat
,fix
,chore
) determined by the AI based on the diff. The AI is instructed to generate this.
-
-
Custom Variables: Any other
{variableName}
(like{scope}
above) is a custom variable.
- Use
-
variables
(object, required): Contains descriptions for your custom variables.- The keys are the custom variable names (e.g.,
"scope"
). - The values are strings describing what information should go into that variable. These descriptions are sent to the AI to help it fill the template correctly.
- If you add a new custom variable to your
format
string,commiat
will prompt you to provide its description the next time you run it, and it will save the description back to your.commiat
file.
- The keys are the custom variable names (e.g.,
Settings are looked for in this order:
-
Environment Variables / Local
.env
File:COMMIAT_OPENROUTER_API_KEY
,COMMIAT_OPENROUTER_MODEL
,COMMIAT_USE_OLLAMA
,COMMIAT_OLLAMA_BASE_URL
,COMMIAT_OLLAMA_MODEL
,COMMIAT_OLLAMA_FALLBACK_TO_OPENROUTER
set in your shell or a project-local.env
file override everything else. -
Project
.commiat
File: If present, theformat
andvariables
defined here are used for commit message generation. -
Global
~/.commiat/config
File: Used for LLM provider settings if not set by environment variables. -
Prompts / Defaults:
- If using OpenRouter and
COMMIAT_OPENROUTER_API_KEY
is not found, you'll be prompted, and it will be saved globally. - If LLM provider settings are not found, defaults are used (OpenRouter with Gemini Flash, or Ollama with llama3 if enabled).
- If
.commiat
is not found, a standard conventional commit format ({type}: {msg}
) is used. If.commiat
is missing custom variable descriptions, you'll be prompted.
- If using OpenRouter and
-
(Optional) Configure your LLM provider:
- For OpenRouter (default): Run
commiat
once. It will prompt for your API key if needed and save it globally. You can edit the model later withcommiat config
. - For Ollama: Run
commiat ollama
to enable it, set the URL/model, and optionally enable fallback to OpenRouter.
- For OpenRouter (default): Run
-
(Optional) Create a
.commiat
file in your project root if you want a custom format (see example above). -
Stage your changes:
git add <your-files...> # OR stage all changes: git add .
-
Run commiat:
# Generate commit message commiat # Stage all changes AND generate commit message commiat -a # or commiat --add-all # Generate commit message and bypass commit hooks commiat -n # or commiat --no-verify # Combine flags commiat -a -n
-
Follow the prompts:
- If it's the first time using a custom variable in
.commiat
, you'll be asked for its description. - Confirm, adjust, or cancel the suggested commit message.
- If it's the first time using a custom variable in
Example Workflow with Custom Format:
- Create
.commiat
:{ "format": "feat({component}): {msg} [JIRA-{gitBranchNumber}]", "variables": { "component": "The UI component or backend module affected" } }
- Assume current branch is
feature/JIRA-456-new-login
. - Make changes, stage them (
git add .
). - Run
commiat
. - AI generates a message like:
feat(Auth): implement new login flow [JIRA-456]
- Confirm or adjust.
-
Edit Global Configuration (Mainly OpenRouter):
Opens
~/.commiat/config
in your editor. Use this primarily for the OpenRouter API key and model if not using environment variables.commiat config
-
Configure Ollama:
Interactively enable/disable Ollama, set its URL and model, and configure fallback to OpenRouter.
commiat ollama
-
Test LLM Configuration:
Checks connection and basic generation using your currently configured provider (OpenRouter OR Ollama w/ fallback).
commiat config --test
Happy committing! 🎉