rule
git staging
Git commit best practices - avoid git add -A, stage files explicitly, always sign off
Set up
Skills are installed by placing their folder where your agent loads skills.
Part of the collection prisma/prisma-next.
Copy the text of git-staging.mdc into the instructions file your agent reads (CLAUDE.md, AGENTS.md, .cursor/rules, …). Written for AI coding agents in general (from where the project keeps it; we have not run it).
README
synced Oct 14, 2026Git Commit Best Practices
Never Use git add -A or git add .
CRITICAL: Do not use git add -A, git add ., or git add --all when staging changes. These commands stage all changes including unrelated or untracked files.
Correct Approach
Always stage files explicitly:
# Stage specific files
git add path/to/file1.ts path/to/file2.ts
# Stage modified files only (doesn't add untracked files)
git add -u
# Stage files matching a pattern (be specific)
git add packages/1-framework/1-core/*/package.json
Always Sign Off Commits
CRITICAL: Every git commit you author MUST include a Signed-off-by: trailer. Pass -s (or --signoff) on every commit.
# Correct
git commit -s -m 'fix(foo): correct null handling in bar'
# Correct (with HEREDOC for multi-line messages)
git commit -s -m "$(cat <<'EOF'
fix(foo): correct null handling in bar
Explains why ...
EOF
)"
# WRONG — no signoff trailer
git commit -m 'fix(foo): correct null handling in bar'
Common pitfalls:
- The
format.signoff=truegit config option only affectsgit format-patch, notgit commit. Do not assume the user's global config will add the trailer. - There is no
commit.signoffgit config option. The trailer must be added explicitly per commit, or via aprepare-commit-msghook owned by the user. - When using
git commit --amend(rare — see "Never Amend Pushed Commits" below), pass--signoffto ensure the trailer is present after the amend. - When rebasing with
--execor--signoff, ensure the trailer is preserved.
Verify before pushing:
# Last commit must show a Signed-off-by line under the message body
git log -1 --format='%B' | tail -3
Never Amend Pushed Commits
Do not use git commit --amend on commits that have already been pushed to the remote. This rewrites history and causes problems for anyone else working with the branch.
Instead, create a new commit with the fix.
Best Practices
- Review before staging: Run
git statusto see what will be staged - Stage explicitly: List the specific files or use
-ufor modified files only - Verify before committing: Run
git diff --cachedto review staged changes - Sign off every commit: Pass
-sto everygit commitinvocation - Keep commits focused: Each commit should contain related changes only
- Don't amend pushed commits: Only amend commits that haven't been pushed yet
Shell-safe commit messages
When using git commit -m, avoid shell interpolation pitfalls:
- Prefer single quotes around
-mmessage strings. - Don’t use backticks in commit messages (they can trigger command substitution in some shells).
A good commit:
- Represents one logical step (a coherent unit of change)
- Explains intent ("why"), not just mechanics ("what")
- Is reviewable on its own (small diff, focused scope)