| git-ac | ||
| README.md | ||
git-ac AI Commit Message (Bash + Ollama or tgpt)
A tiny Bash helper that generates ultra-short Git commit messages from your staged changes, asks you to confirm/edit, and commits.
- Default engine: Ollama with the
gpt-oss:20b-cloudmodel (ollama cloud). - Alternative engine: tgpt (CLI chatbot without API keys).
- If generation fails, it falls back to manual input.
How it works
git add .- Read the staged diff (
git diff --cached). If empty → exit. - Ask an LLM for a very short commit message.
- Show it, then:
- Y: commit,
- n: cancel,
- e: open in
$EDITOR, then commit.
Requirements
- Git, Bash (Linux/macOS; on Windows use Git Bash or WSL).
- For Ollama mode:
- Install Ollama and have the
mistralmodel available. :contentReference[oaicite:0]{index=0}
- Install Ollama and have the
- For tgpt mode (optional):
- Install tgpt (cross-platform CLI; no API keys required). :contentReference[oaicite:1]{index=1}
Install
-
Save the script as
git-acin your repo (or somewhere inPATH). -
Make it executable:
chmod +x git-ac -
(Optional) choose the editor used by
e:export EDITOR=micro # or nano, geany, vim, ...
Using Ollama (default)
-
Install Ollama
-
Linux/macOS:
curl -fsSL https://ollama.com/install.sh | sh([Ollama][1])
-
Windows: download the installer from the official site. ([Ollama][2])
-
-
Get the model (pulled automatically on first run):
ollama run mistral "hello"([Ollama][3])
-
Run the script inside your Git repo:
./git-ac
Switching to tgpt (optional)
If you prefer tgpt instead of Ollama, install it and swap two lines in the script.
Install tgpt
Pick one method (see repo for others):
-
Linux/macOS (install script to
/usr/local/bin):curl -sSL https://raw.githubusercontent.com/aandrew-me/tgpt/main/install | bash -s /usr/local/bin -
Homebrew:
brew install tgpt -
Go:
go install github.com/aandrew-me/tgpt/v2@latest -
Windows (PowerShell):
irm https://raw.githubusercontent.com/aandrew-me/tgpt/refs/heads/main/install-win.ps1 | iex([GitHub][4])
Minimal code change
Replace the Ollama line:
msg=$(ollama run mistral "Write a very short git commit message from:\n$diff")
with the tgpt block that also cleans spinners/fences:
raw=$(tgpt "Write ONLY a very short git commit message from:\n$diff")
msg=$(echo "$raw" | sed 's/.*Loading[[:space:]]*//' | sed 's/^[[:space:]]*//' | sed -n '/^```/{n;:a;/^```/q;p;n;ba}')
Notes
tgptsometimes prints a “Loading …” spinner or wraps output in ````` code fences; that one-liner strips both.- Keep the prompt strict (“ONLY a very short…”) to avoid verbose outputs.
Tips
- Want even shorter messages? Soften the prompt to “ONE line, max 8 words”.
- Prefer imperative style? Add “Use imperative tense” to the prompt.
- Different Ollama model? Replace
mistralwith any installed model, e.g.gemma:2b,llama3.2:1b. ([GitHub][5])
Troubleshooting
No changes to commit.You forgot to stage files. Rungit add -porgit add ..ollama: command not foundInstall Ollama and/or restart your shell soPATHis updated. ([Ollama][1])model not foundor long first run Ollama downloads the model on first use; wait formistralto pull. ([Ollama][3])tgpt: command not foundInstall tgpt via script/Homebrew/Go/Windows installer. ([GitHub][4])
License
MIT (for this script). Ollama, models, and tgpt are licensed separately—see their repos/websites.
[1]: https://ollama.com/download?utm_source=chatgpt.com "Download Ollama on Linux"
[2]: https://ollama.com/download/windows?utm_source=chatgpt.com "Download Ollama on Windows"
[3]: https://ollama.com/library/mistral?utm_source=chatgpt.com "mistral"
[4]: https://github.com/aandrew-me/tgpt "GitHub - aandrew-me/tgpt: AI Chatbots in terminal without needing API keys"
[5]: https://github.com/ollama/ollama?utm_source=chatgpt.com "ollama/ollama: Get up and running with OpenAI gpt-oss, ..."