A lightweight, dual-mode TortoiseGit hook & CLI tool that automatically generates clean, informative commit messages in Conventional Commits format using any OpenAI-compatible AI backend (local Ollama, LM Studio, OpenAI, OpenRouter, etc.).
- π― Dual Mode Operation:
- TortoiseGit Hook: Automatically pre-fills the TortoiseGit commit message area upon opening the commit dialog.
- Standalone CLI: Run
ai-commitdirectly in your favorite terminal (CMD, PowerShell, Windows Terminal) with formatted console output.
- π Universal OpenAI-Compatible API: Works seamlessly with local models via Ollama or LM Studio, as well as cloud providers like OpenAI, OpenRouter, or Groq.
- β‘ Instant Provider Profiles: Switch between configured providers (Ollama, OpenAI, LM Studio, etc.) by changing a single word (
$AI_ACTIVE_PROFILE). - π Modular Commit Formats: Easily switch between built-in format templates or add your own in the
prompts/directory:conventional-body(default: subject line + bullet points with dashes)conventional(single-line summary)gitmoji(emoji-prefixed conventional commits)
- π Deep Function Context (
-w/--context): Usegit diff -Wto provide the LLM with the entire enclosing function context, producing far more accurate commit descriptions for localized changes. - π― Targeted File Selection: Pass specific files directly in the CLI (
ai-commit file1 file2) to generate messages exclusively for those changes. - π§Ή Smart Draft & Scratchpad Filter: Automatically exclude untracked drafts, notes, or scratchpads using customizable glob patterns (
$AI_EXCLUDE). - π Universal Multilingual Support: Supports any ISO 639-1 language code (
en,ru,de,es,fr,ja, etc.) or full language name via built-in .NETCultureInfo. - π οΈ PowerShell 5.1 Mojibake Auto-Fix: Contains built-in byte reconstruction to prevent Windows PowerShell encoding bugs with Cyrillic or special characters.
tortoise-ai-commit/
βββ prompts/
β βββ conventional-body.txt # Default: subject + bullet points with dashes
β βββ conventional.txt # Single-line conventional commit
β βββ gitmoji.txt # Gitmoji conventional commit
βββ ai-commit.ps1 # Main hook and CLI engine
βββ ai-commit.cmd # Command wrapper for fast terminal execution
βββ environment.example.ps1 # Configuration template (copy to environment.ps1)
βββ .gitignore # Excludes local secrets (environment.ps1)
βββ LICENSE # MIT License
βββ README.md
Clone this repository to a stable directory on your machine (e.g., C:\Tools\tortoise-ai-commit):
git clone https://github.com/goloveshko/tortoise-ai-commit.git C:\Tools\tortoise-ai-commit- In the project folder, duplicate
environment.example.ps1and rename it toenvironment.ps1. - Open
environment.ps1and adjust your preferences:- Active Profile: Set
$AI_ACTIVE_PROFILE = "ollama"(or"openai","lm-studio","openrouter"). - Format: Choose
$AI_FORMAT = "conventional-body"(or"conventional","gitmoji"). - Language: Set
$AI_LANGUAGE = "en"(or"ru","de","es", etc.). - Exclusions: Modify
$AI_EXCLUDEfor draft/temporary files.
- Active Profile: Set
π‘ Recommended local model:
qwen2.5-coder:7b. It is fast, lightweight, and excels at understanding Git diffs.
To run ai-commit from anywhere in any terminal:
- Add
C:\Tools\tortoise-ai-committo your Windows PATH environment variable. - Open any terminal in any Git repository and run:
# Generate commit message for all staged/unstaged changes:
ai-commit
# Generate with full function context (-W / --function-context):
ai-commit -w
# Generate only for specific files:
ai-commit src/main.cpp include/config.h
# Combine flags and specific files:
ai-commit -w src/auth.goTo have commit messages generated automatically when opening TortoiseGit:
- Right-click anywhere in Windows Explorer and open TortoiseGit β Settings.
- In the left navigation tree, select Hook Scripts.
- Click Add...:
- Hook Type: Select
Start Commit Hook. - Run when working tree path is under: Enter
*(asterisk applies the hook to all repositories) or specify a particular repository path. - Command Line To Execute:
(
powershell.exe -ExecutionPolicy Bypass -File "C:\Tools\tortoise-ai-commit\ai-commit.ps1"β οΈ Adjust to your actual path. Do NOT append%1or%2β TortoiseGit appends them automatically). - Wait for the script to finish: β Checked.
- Hide the script while running: β Checked.
- Enable: β Checked (at the top of the dialog).
- Hook Type: Select
- Click OK and Apply.
β±οΈ Note on TortoiseGit Delay: When clicking Git Commit..., the dialog will take 2 to 5 seconds to appear. This delay occurs because the hook queries the LLM and pre-fills the message before the window is rendered.
Create a new text file inside the prompts/ directory (e.g., prompts/my-style.txt). In your environment.ps1, specify:
$AI_FORMAT = "my-style"Use {{LANG_INSTRUCTION}} inside your prompt file to allow dynamic language substitution.
If you always want the AI to analyze entire functions instead of small diff hunks, enable it in environment.ps1:
$AI_EXPAND_CONTEXT = $trueIf the AI server is unreachable, times out, or returns an error, the script will write an error description directly into the commit text box (or terminal output).
- If using Ollama, verify that the service is running (
ollama listor check the system tray). - Verify that the model specified in your profile is downloaded (
ollama pull qwen2.5-coder:7b). - Check your network connection and API keys for cloud providers.
If PowerShell scripts are restricted on your system, ensure -ExecutionPolicy Bypass is included in the hook command:
powershell.exe -ExecutionPolicy Bypass -File "C:\Tools\tortoise-ai-commit\ai-commit.ps1"This project is licensed under the MIT License.
Developed with β€οΈ by a professional C++ & Qt developer.
- Telegram Support Bot: @itz2bot
- Portfolio: sergey.is-a.dev
- GitHub Issues: Report a bug
