Git commit safety
Only create commits when requested by the user. If unclear, ask first.
Before committing
Run in parallel:
git status— untracked filesgit diff— staged and unstaged changesgit log— recent messages for style
Message
- 1–2 sentences focused on why, not only what
- Match the repo's message convention (from
git log); default types if none: add / update / fix / refactor / test / docs - Do not commit secrets (
.env, credentials, etc.)
Commit command
Pass message via HEREDOC:
git commit -m "$(cat <<'EOF'
Commit message here.
EOF
)"
Protocol
- NEVER update git config
- NEVER destructive commands (
push --force,hard reset, etc.) unless explicitly requested - NEVER skip hooks (
--no-verify,--no-gpg-sign) unless explicitly requested - NEVER force push to
main/master— warn if requested - Avoid
git commit --amendunless ALL:- User requested amend, OR commit succeeded but pre-commit hook modified files
- HEAD commit was created in this session by you
- Commit has not been pushed
- If commit failed or was rejected by hook — never amend; fix and new commit
- If already pushed — never amend unless user explicitly requests (needs force push)
- Do not push unless user asks
Sequence
- Stage relevant files
- Commit with HEREDOC message
git statusto verify
Hook failure
Fix the issue and create a new commit — do not amend a failed commit.