prepare-commit-msg git hook that sends your staged diff to Nito and prefills the commit-message editor with a suggestion you can accept or edit. It fails open: if Nito is unavailable, the commit proceeds untouched, so the hook can never block your work.
When to reach for it. Any repo where you want consistent one-line commit messages without the friction. It runs locally on every git commit.
How It Works
Git runs aprepare-commit-msg hook after you type git commit but before the editor opens, and passes it the path to the commit-message file (and, for some commit types, a source). The hook reads your staged diff, pipes it to nito ask --stdin --quiet, and writes the one-line suggestion into that file, where it appears prefilled in your editor.
Two design choices keep it safe:
- It only prefills a plain
git commit. Forgit commit -m, merges, squashes, and amends, the message already exists, and git sets a commit source in those cases. The hook checks for that source and exits without touching anything. - It fails open. The suggestion is written only if
nito asksucceeded. If Nito is down or you are offline, the commit proceeds with the normal empty template. A helper that blocks commits would be worse than no helper.
Prerequisites
- Nito installed and signed in. See Nito CLI.
- A git repository.
Step 1: Install the hook
Save this as.git/hooks/prepare-commit-msg in your repo and make it executable (chmod +x .git/hooks/prepare-commit-msg):
COMMIT_SOURCEguard skips the hook whenever a message already exists, so it only prefills a plaingit commit.--stdintakes the whole prompt from the pipe, so the instruction and the diff go in together.--quietreturns only the message text, nothing to strip.if suggestion=$(…); thenwrites the file only on success, which is what makes the hook fail open.
Step 2: Use it
Step 3: Test it without committing
To see what the hook would produce without making a commit, run its core against your staged changes directly:Variations
Team-shared hook..git/hooks is not committed, so it is per-clone. To share the hook across a team, keep it in the repo (for example scripts/hooks/) and point git at that directory once:
nito ask line:
Troubleshooting
Where to Go Next
Private Code Review Pipeline
Review the same staged diff across models before you commit.
Scripting and Automation
Exit codes, stdin, and output modes for hooks and pipelines.

