Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Verify that the current Git branch, upstream state, and dirty working tree match the user's intended task before staging, committing, pushing, or continuing work from another session. Use this to detect stale branch reuse, leftover dirty files from previous sessions, unrelated commits on the current branch, cases where work should be split into a new branch or worktree, and post-publish cleanup decisions after push, PR creation, or PR merge.
| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-04 | ✗→✓ | ▲ Improved | 244% | 0% |
| case-05 | ✗→✓ | ▲ Improved | 228% | 0% |
| case-10 | ✗→✓ | ▲ Improved | 226% | 0% |
| case-11 | ✗→✓ | ▲ Improved | 216% | 0% |
| case-17 | ✗→✓ | ▲ Improved | 251% | 0% |
Type: Execution
Prevent accidental commits on the wrong branch or into a dirty working tree owned by another session.
This skill verifies:
forward
continuing work
creation, or PR merge
session
to switch back to base, delete local/remote branches, or remove worktrees
for this exact task
Do not run this skill without:
Optional but recommended:
main, develop, release branch)match, ambiguous, mismatch, or blocked)Summarize the current task in one sentence before inspecting Git.
Extract these intent signals when available:
If intent cannot be summarized, ask the user for a short task description before recommending any Git action.
Collect evidence with non-destructive commands:
git status --short --branchgit branch --show-currentgit diff --name-onlygit diff --cached --name-onlygit log --oneline --decorate -5When useful and available, also check:
git rev-parse --abbrev-ref --symbolic-full-name @{u} for upstream branchgit status --porcelain=v1 for machine-readable dirty filesgit merge-base --fork-point <base> HEAD or git merge-base <base> HEADwhen evaluating whether branch commits are tied to the expected base
Do not run commands that alter the index, working tree, branch, or stash.
Infer the current branch's likely purpose from:
feature/foo, ticket IDs, user names, session IDs)main, master,develop, release/*, or hotfix/*
Compare that inferred purpose against the current task intent from Gate 0.
Classify the result:
current task.
needs user confirmation.
session.
without a user decision.
Separate files into:
explicitly requested by the user.
or are not attributable to this session.
Then check overlap:
If overlap exists, classify the verdict as blocked unless the user explicitly confirms the combined scope.
Use this matrix to recommend the next action:
| Condition | Verdict | Recommended Action | |---|---|---| | Branch matches current task and dirty files are in-scope | match | Continue finalize, stage only confirmed files | | Branch is generic or evidence is weak, but no conflicting dirty files exist | ambiguous | Ask user to confirm branch before commit | | Clean branch clearly belongs to another task | mismatch | Create/switch to a task-appropriate branch or worktree before editing/committing | | Dirty branch contains previous-session work unrelated to current task | blocked | Do not commit; ask whether to finish previous work, split via worktree, or isolate current-session patch | | Current branch is protected/shared and task is non-trivial | blocked | Create a feature/fix branch before committing | | Staged files include unknown or unrelated changes | blocked | Unstage only with explicit user approval; otherwise stop before commit | | Branch is ahead of upstream with unrelated commits | mismatch | Do not add new task commits; create a separate branch from the correct base or ask user to confirm stacking |
When recommending a new branch, propose a concrete name derived from the task, for example fix/login-timeout or docs/branch-guard.
When recommending a worktree, include the base branch assumption and state that only user-confirmed changes should be moved or recreated there.
Before any staging or commit:
ambiguous, mismatch, orblocked.
If used inside finalize-and-commit or docs-finalize-and-commit, this gate must complete before their Working Set Validation gate proceeds.
Run this gate after any commit/push/PR operation before ending the workflow. The agent must either perform an approved cleanup or explicitly state why no cleanup was performed.
Step 6-1: Capture publish state
Inspect:
git status --short --branchgit branch --show-currentgit worktree listgit branch --format='%(refname:short) %(upstream:short)'OPEN, MERGED, CLOSED) and merge commit when a PR existsUse gh pr view or equivalent repository tooling when available. If GitHub metadata is unavailable, do not infer that a branch is merged from Git alone when squash merge may have been used.
Step 6-2: Present cleanup choices
Offer the applicable choices instead of silently ending:
open PR.
merged or closed intentionally.
clean and no longer needed.
cleanup.
If the user explicitly requested cleanup, execute every eligible cleanup step after the safety checks below pass. If the user did not request cleanup, stop and ask which option to apply.
Step 6-3: Safety checks before deletion
Deletion is eligible only when all relevant checks pass:
MERGED, or the user explicitly confirms thatthe branch is obsolete.
user confirms that dependency is gone.
git status inside that worktree is clean.Prefer git branch -d. If squash merge makes git branch -d reject a branch whose PR is confirmed MERGED, use git branch -D only after stating that reason and only for the task branch.
Step 6-4: Verification after cleanup
After cleanup, verify and report:
git status --short --branchgit worktree listout.
commits, dirty files, and task intent.
reset, checkout --, restore,clean, stash, rebase, branch deletion) without explicit user approval.
git add ., git add -A, or git add --all.statement that cleanup is not applicable yet.
checks in Gate 6 pass.
stay until merge or an explicit user decision.
separate clean worktree path.
Common bad outputs:
previous task
current request
git stash as a default solution, hiding ownership instead ofclarifying it
should be main or develop
files that caused the risk
mentioning cleanup choices
Input:
Current task: add billing export tests. git status --short --branch shows a clean working tree on feature/oauth-login. Recent commits mention OAuth callback handling.
Output:
feature/oauth-login, clean tree, recentcommits are OAuth-related.
mismatch — current task is billing export tests, butbranch intent is OAuth login.
test/billing-export, before making or committing billing changes.
main assumed) andnew branch/worktree preference.
Input:
Current task: update dashboard copy. Current branch is agent/aaa-refactor. Working tree has modified src/auth/session.ts and src/dashboard/Home.tsx. Conversation history only touched src/dashboard/Home.tsx. Recent commits on the branch mention auth session refactoring.
Output:
agent/aaa-refactor, dirty files in auth anddashboard, recent commits are auth-related.
blocked — branch and one dirty file appear to belongto a previous auth refactor session.
src/dashboard/Home.tsx is current-session;src/auth/session.ts is carried-forward/unknown.
auth refactor first, create a separate worktree for dashboard copy, or commit only the confirmed dashboard file after explicit approval.
staging.
This skill is intentionally conservative. Its goal is not to automate branch management; it is to prevent accidental task mixing at the commit boundary.
Other measured skills in the registry, with their headline benchmark lift.