2.6 KiB
Use this skill when the user wants to commit changes to git. Trigger if the user says "commit", "save changes", "commit this", or asks to create a git commit. Examples: "commit", "commit and push", "save my changes".
Process
-
Assess the working tree — Run
git status(never use-uall) andgit diff --stagedandgit diffto understand what changed. -
Guard rails — Before staging:
- Never commit files that contain secrets (
.env, credentials, tokens, keys). Warn if any are present. - Never commit build artifacts (
dist/,*.tsbuildinfo). - Never commit
node_modules/. - If there are no changes to commit, say so and stop.
- Never commit files that contain secrets (
-
Stage selectively — Stage files by name. Prefer
git add <file>...overgit add -Aorgit add .to avoid accidentally including sensitive or unrelated files. Group related changes — if unrelated changes exist, ask whether to commit everything together or separately. -
Write the commit message — Use Conventional Commits format:
feat:new featurefix:bug fixrefactor:code restructuring without behavior changechore:maintenance, dependencies, configdocs:documentation onlystyle:formatting, whitespacetest:adding or updating tests- Scope is optional:
feat(whatsapp): add voice note transcription - Subject line: imperative mood, lowercase, no period, under 72 chars
- Body (if needed): blank line after subject, wrap at 72 chars, explain why not what
- Always end with:
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
-
Commit — Use a HEREDOC for the message to preserve formatting:
git commit -m "$(cat <<'EOF' type(scope): subject line Optional body explaining why. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> EOF )" -
Verify — Run
git statusafter committing to confirm success. Show the resultinggit log --oneline -1.
Rules
- Never push unless
$ARGUMENTScontains "and push" or "push". - Never amend unless
$ARGUMENTScontains "amend". - Never skip hooks (no
--no-verify). - Never force push.
- If a pre-commit hook fails, fix the issue, re-stage, and create a new commit (do not amend).
- If
$ARGUMENTScontains a message hint, use it to inform the commit message but still follow conventional format.
Arguments
$ARGUMENTS — Optional. May contain:
- A message hint (e.g.,
/commit add voice transcription support) - "and push" to push after committing
- "amend" to amend the previous commit instead of creating a new one
- "all" to stage all changes without asking