CommitAI lets you automate meaningful commit messages effortlessly using the CLI with cmt
. In just two seconds, your staged changes are committed with an AI-generated message.
-
Install CommitAI globally for use in any repository:
npm install -g @mantisware/commit-ai
-
Obtain an API key from OpenAI or another supported LLM provider. Ensure your OpenAI account has an active payment method for API access.
-
Configure CommitAI with your API key:
cmt config set CMT_API_KEY=<your_api_key>
The API key is stored securely in
~/.commit-ai
.
To generate a commit message for staged changes, run:
git add <files...>
cmt
Running git add
is optional—cmt
will automatically stage changes for you.
You can also run CommitAI with a local model through Ollama:
- Install and start Ollama.
- Execute
ollama run mistral
(only once, to pull the model). - In your project directory, configure CommitAI:
git add <files...>
cmt config set CMT_AI_PROVIDER='ollama' CMT_MODEL='llama3:8b'
By default, the model used is mistral
.
If Ollama runs on another machine or within Docker with GPU support, update the API endpoint:
cmt config set CMT_API_URL='http://192.168.1.10:11434/api/chat'
Replace 192.168.1.10
with the appropriate endpoint.
You can also run CommitAI with a local model through LM Studio:
- Install and start LM Studio.
- Add the DeepSeekCoder model to your project. current:
deepseek-coder-v2-lite-instruct
or for macosdeepseek-coder-v2-lite-instruct-mlx
- In your
~/.commit-ai
configure CommitAI:
cmt config set CMT_MODEL='deepseek-coder-v2-lite-instruct-mlx' CMT_API_URL='http://127.0.0.1:1234' CMT_AI_PROVIDER='deepseek'
Replace http://127.0.0.1:1234
with the appropriate endpoint provided by LM Studio.
Add CommitAI configurations to a .env
file in your repository:
CMT_AI_PROVIDER=<openai (default), anthropic, azure, ollama, gemini, flowise, mlx, deepseek>
CMT_API_KEY=<your OpenAI API token> # or another LLM provider API key
CMT_API_URL=<optional proxy path to OpenAI API>
CMT_TOKENS_MAX_INPUT=4096 # Maximum input tokens (default: 4096)
CMT_TOKENS_MAX_OUTPUT=500 # Maximum output tokens (default: 500)
CMT_DESCRIPTION=true # Append a brief description of changes
CMT_EMOJI=true # Enable GitMoji support
CMT_MODEL='gpt-4o' # Set AI model (e.g., 'gpt-4o', 'gpt-3.5-turbo')
CMT_LANGUAGE='en' # Language preference
CMT_MESSAGE_TEMPLATE_PLACEHOLDER='$msg' # Message template placeholder
CMT_PROMPT_MODULE='conventional-commit' # Use 'conventional-commit' or '@commitlint'
CMT_ONE_LINE_COMMIT=false # Single-line commit messages
Global settings are stored in ~/.commit-ai
and configured with:
cmt config set CMT_MODEL=gpt-4o
Local settings take precedence over global configurations.
By default, CommitAI limits GitMoji to 10 emojis (🐛✨📝🚀✅♻️⬆️🔧🌐💡) to optimize API usage. To enable full GitMoji support:
cmt --fgm
Ensure CMT_EMOJI
is set to true
.
To commit changes without requiring manual confirmation:
cmt --yes
Prevent CommitAI from processing certain files by creating a .commit-aiignore
file:
path/to/large-asset.zip
**/*.jpg
By default, CommitAI ignores files like *-lock.*
and *.lock
.
CommitAI can integrate as a Git prepare-commit-msg
hook for seamless commit message generation within your IDE.
To enable:
cmt hook set
To disable:
cmt hook unset
To use the hook:
git add <files...>
git commit
CommitAI can enhance commit messages automatically when pushing to a remote repository.
- Create
.github/workflows/commit-ai.yml
with:
name: 'CommitAI Action'
on:
push:
branches-ignore: [main, master, dev, development, release]
jobs:
commit-ai:
runs-on: ubuntu-latest
permissions: write-all
steps:
- name: Set Up Node.js
uses: actions/setup-node@v2
with:
node-version: '16'
- uses: actions/checkout@v3
- uses: MantisWare/commit-ai@github-action-v1.0.4
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
env:
CMT_API_KEY: ${{ secrets.CMT_API_KEY }}
CMT_MODEL: gpt-4o
CMT_LANGUAGE: en
Ensure the OpenAI API key is stored as a GitHub secret (CMT_API_KEY
).
CommitAI uses OpenAI API, and you are responsible for associated costs.
By default, it uses gpt-3.5-turbo
, which should not exceed $0.10 per workday. Upgrading to gpt-4o
improves quality but increases cost.