When to use
- The user asks you to commit, write a commit message, or "save this to git".
Never commit on your own initiative, even at the end of a task.
Before you start
- Check the repo state with
git status --shortand the current branch withgit branch --show-current. - If changes are already staged, the commit covers only those. If nothing is staged, ask which files to include; never stage unrelated changes or files you didn't touch without asking.
- Check for a project commit convention (Conventional Commits,
commitlint.config.*, aCONTRIBUTING.mdsection, a commit template). If one exists, follow it and keep the dash-list body below the required header. Otherwise use the format below.
Steps
-
Inspect the changes with git. Read the actual diff, not just file names:
git diff --staged --stat git diff --staged(Use
git difffor unstaged changes the user wants to include, after they confirm.) -
Make notes of what changed, grouped by intent rather than by file.
-
Draft the message as a dash list, one line per change:
- concise, in present tense ("Add", "Fix", "Remove", not "Added" or "Adds");
- focused on what changed, not how you did it;
- short lines; keep the whole message small. Split unrelated work into separate commits instead of one long message.
-
Show the message as plain text and ask for approval. Show only the message, not the command:
- Add rate limiting to the login endpoint - Fix the empty-state message on the orders page - Remove the unused date helperWait for the user to approve or edit it.
-
Scan staged files for secrets if gitleaks is installed (see
secrets-scan):gitleaks git --staged --redact --no-banner -vIf it finds anything, stop, tell the user what and where (never the value), and follow
secrets-scan. If gitleaks isn't installed, check the diff yourself for keys, tokens, passwords,.envfiles and private keys, and say that you did a manual check. -
Commit with the approved lines, one argument per line:
printf '%s\n' "- Add rate limiting to the login endpoint" "- Fix the empty-state message on the orders page" | git commit -F -If a line contains
",$or a backtick, wrap that argument in single quotes instead. Add any trailer lines the project or tool requires (for exampleCo-Authored-By:) after an empty""argument. -
Report the short commit hash and the subject line (
git log --oneline -1).
Verify
git log -1 --format=%Bshows exactly the approved message.git status --shortshows only the changes the user chose to leave uncommitted.- Hooks ran and passed. If a pre-commit hook failed, the commit didn't happen: fix the cause, re-stage, and ask again before retrying.
Safety
- Never commit without the user's approval of the message.
- Never commit secrets,
.envfiles, private keys or credentials. If the user insists, explain that anything committed must be treated as leaked, suggest a secret manager, and let them make that commit themselves. - Never use
--no-verify,--amendon pushed commits,git commit -awithout confirming, orgit push, unless the user explicitly asks. - Never change git config, hooks or author identity.