co
Commit changes with logical grouping and conventional messages, optionally push. Use when the user says 'commit', 'commits', 'save changes', or '/co', or when finished work needs committing. `/co auto
SKILL.mdskills/co/SKILL.md
GitHubco — commit utility
Arguments
Parse $ARGUMENTS case-insensitively, hyphens optional:
push— also push after committing.auto— for the rest of the session, commit after each meaningful unit of work (feature, fix, refactor) without asking. Then commit whatever is pending now.forbid— for the rest of the session, make NO commits unless the user explicitly asks (an explicit/costill commits, and does not lift the mode). For try-and-error development. Set the mode, confirm in one line, and stop — commit nothing now.--no-push/--nopush— invoke/push-forbidbefore committing.--push-auto/--pushauto/--push-ok/--pushok— invoke/push-autobefore committing.
auto and forbid are explicit user choices: apply them immediately, no confirmation question. They are session instructions like /push-auto / /push-forbid, not stored state, and are independent of the push mode. Under auto, still ask when unsure whether a specific file belongs in a commit.
Execution — keep the diff out of the main context
The commit work runs in a Haiku subagent so the main session sees only a summary, never the git diff, file-selection reasoning, or message drafting.
Step 0: Pre-check
git status --porcelain
git rev-list --count @{upstream}..HEAD 2>/dev/null || echo "unknown"
- Nothing to commit, nothing ahead → report "Nothing to commit or push." and stop.
- Nothing to commit,
pushgiven → no subagent. Ahead: push per the Push rules below.unknown(no upstream):git push -u origin $(git branch --show-current). Report and stop. - Nothing to commit, N ahead, no
push→ report "Nothing to commit. N commit(s) ahead of remote — use/co pushto push." and stop. - Something to commit → Attempt 1.
Attempt 1: Haiku subagent
Spawn an Agent with model: "haiku". Its prompt is the Instructions section below plus the repo path, whether push was requested, and the session's Co-Authored-By line if the session specifies one. On success, relay its report and stop.
Attempt 2: direct execution (last resort)
Only if the subagent failed (partial commits, conflict, any error): run git status and git log --oneline to see where it stopped, then carry out the Instructions for the remainder in this session.
Instructions
Inspect —
git status,git diff --stat.Keep junk out via
.gitignore. If the status shows files that must never be committed — dependencies (node_modules/), build output (dist/,build/,.next/,out/), logs, temp/swap files, OS files (.DS_Store,Thumbs.db), caches, coverage, env files (.env*), secrets (*.pem,*.key,credentials.json) — add the missing patterns to.gitignore(create it if the project has none), andgit reset HEAD <file>anything already staged. If such a file is already in history, tell the user. IDE dirs and lockfiles are context-dependent: follow the repo's existing practice.Stray images are the exception — NEVER add image globs (
*.pngetc.) to.gitignore; that can silently exclude real assets. Images in the repo root or non-content dirs are usually headless-browser or conversation leftovers: delete them if no longer needed, otherwise move them out:LOGDIR=$(node $HOME/.claude/scripts/get-logdir.js) && mkdir -p "$LOGDIR" && mv <file> "$LOGDIR/".Stage selectively — never a blind
git add .. Only intentional, meaningful changes; skip auto-generated noise. Unsure about a file → ask.Group — one commit when changes are small and related; separate commits for unrelated concerns (docs vs code, feature vs fix, refactor vs new behavior, config vs source). Prefer small focused commits.
Commit — conventional style (
feat:,fix:,docs:,refactor:, …), HEREDOC message, ending with the Co-Authored-By line you were given, elseCo-Authored-By: Claude <noreply@anthropic.com>:git commit -m "$(cat <<'EOF' feat: message here Co-Authored-By: Claude <noreply@anthropic.com> EOF )"Push — only if
pushwas requested; see Push rules.Verify —
git statusis clean; showgit log --oneline -n <commits made>.
Never git commit --amend and never force-push without explicit user permission — always make new commits.
Push rules
git rev-list --count @{upstream}..HEAD: 0 → nothing to push.unknown→git push -u origin $(git branch --show-current).- Otherwise check whether the branch is actually behind before pulling anything:
git fetch && git rev-list --count HEAD..@{upstream}. - 0 (not behind) →
git pushdirectly. Do NOT pull. A pull is a no-op at best; with--rebaseit replays every local commit, flattening any merge commit on the branch and re-applying its contents as fresh work — manufacturing conflicts (typically lockfiles) where there was nothing to reconcile. - Non-zero →
git pull --no-rebase(regular merge; never rebase), thengit push.
Conflict during the pull
First re-check the behind-count. If it is 0 the pull should never have run: git merge --abort, plain git push, and treat the conflict as an artifact.
- Haiku subagent, or a child agent in a team: do NOT resolve.
git merge --abort, then report the branch name and conflict details to the caller/manager, who has the full picture. - Main session, standalone:
git merge --abort, inspect incoming work withgit log --oneline HEAD..@{upstream}, pull again to see the conflicts. Trivial (whitespace, non-overlapping) → resolve, commit, push. Overlapping logic or unclear intent → abort again and resolve deliberately with full knowledge of what was implemented before retrying.