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. - π¦ Index-First Accuracy: By default the tool analyzes only the Git index (
git diff --cached), so the message describes exactly what will be committed. Untracked files and unstaged edits are never mentioned. Use--all(or$AI_INCLUDE_UNSTAGED = $true) to widen the analysis to the whole working tree. - π§Ή Smart Draft & Scratchpad Filter: Automatically exclude 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. - π οΈ Correct UTF-8 Everywhere: Responses are decoded from raw bytes with explicit UTF-8, so Cyrillic and other non-ASCII commit messages never turn into mojibake even in Windows PowerShell 5.1.
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 a message for the staged changes (Git index) only:
ai-commit
# Generate with full function context (-W / --function-context):
ai-commit -w
# Include unstaged changes and untracked files as well:
ai-commit --all
# Generate only for specific files:
ai-commit src/main.cpp include/config.h
# Combine flags and specific files:
ai-commit -w src/auth.goπ¦ What gets analyzed: by default the tool reads
git diff --cached, i.e. only what you have staged withgit add. Files that just sit in the folder (untracked) and unstaged edits are ignored, so the generated message never mentions changes that will not be committed. Add--allwhen you want the whole working tree (staged + unstaged + untracked) described instead.
To 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 = $trueThe default scope is the Git index β only staged changes are described. To make the tool analyze every change in the working tree (staged + unstaged + untracked files) on every run, enable it globally:
$AI_INCLUDE_UNSTAGED = $trueThis is especially handy for the TortoiseGit hook, where CLI flags cannot be passed.
If 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
