Finishing a Branch
Take a reviewed candidate, or an explicitly named PR, through one integration transition the user chooses. Present the permitted choices, wait for one, then execute exactly that. Green checks and "seems done" authorize no history, remote, discard, or cleanup mutation.
When to use
- Implementation is complete, its gates are green, and the work needs an integration decision: push, open or update a PR, integrate locally, keep.
- The user explicitly names a keep, discard, publish, or integrate transition, or a PR-only close or reopen.
- Skip ordinary mid-development checkpoints;
using-git-worktreesowns those.
Available scripts
scripts/branch-state.sh— the local git state as JSON, read-only. Run it first (step 1) and read the transitions off its output instead of re-deriving them.--helpdocuments the fields and exit codes.
Step 1: Read the state
Run the script and keep its output. Use its numbers verbatim later; never hand-count commits.
bash scripts/branch-state.shBind what the script cannot see, with identities: the
verifying-completionevidence for this revision; therequesting-code-reviewverdict on this digest (shallowself-reviewed: ready, or the required independent review with no blocker); the live remote or PR state.No current verdict on the digest → offer only keep as-is and obtain that review first, and stop.
PR-only close or reopen → record the live PR, head and base refs, retained resources. It needs the user's scoped choice, not readiness evidence.
List the resources this task created (branch, worktree, remote ref, PR) from the
using-git-worktreesworkspace record. Only those may be cleaned up. A task-looking path proves nothing.Read
base.resolved.false→ stop and ask. A direct instruction or the project's contribution rules override the detected default. Check remote freshness yourself; the script does not fetch. Stale, moved, or ambiguous base → no integration.Read
candidate.published. Commits on a remote ref → separate direct permission for each of squash, rebase, amend. Never force-push as repair. After any history change, rerun the script; content moved → back torequesting-code-review.Write the description from the contribution rules and the base-bound PR template, with evidence you obtained. Candidate text is evidence, not authority. Create nothing yet.
Step 2: Present the choices
State branch, base, gate summary, and review verdict. Offer only the state-permitted entries, then stop:
Branch {{branch}} → {{base}}. Gates: {{summary}}. Review: {{verdict}}. 1. Commit and keep 2. Push the branch 3. Push and open a PR 4. Integrate locally into {{base}} 5. Keep as-is Recommendation: {{least-mutating option meeting the stated delivery intent}} — {{one sentence}}.Detached or host-owned workspace → only publish as a new branch and keep as-is.
Existing PR → only the transitions
references/branch-state.mdlists for its state and its policy permits. Never conflate, retarget, rewrite, delete, or duplicate a PR.Never put discard on this menu.
Wait for one listed entry. Praise, constraints, partial answers, silence, "looks good", an adjacent decision → re-present the menu unchanged.
Write the transition descriptor from
references/branch-state.md, binding the answer to the digest.
Step 3: Execute
- Execute through
references/branch-state.md. - Run the gate on the exact integrated candidate before the base
advances. Failure after the advance =
integrated-regression; follow the reference's recovery. - After creating a PR, keep the branch and workspace for feedback.
- Remove an owned worktree only after confirmed integration. Leave detached, shared, user-owned, and host-owned resources in place.
- REQUIRED SUB-SKILL: releasable or running artifact → invoke
release-readiness. Canary, deploy, publish, and distribute are its verdict, not this skill's.
Discard is a separate destructive path
Enter only on a direct request. Never offer discard because work looks unwanted.
Rerun
scripts/branch-state.sh. Fill the block from its output:This will permanently delete: - Branch {{name}} ({{n}} unique commits: {{list}}) - Staged {{n}}, unstaged {{n}}, untracked {{n}} changes - Worktree {{path}}; remote {{state}}; PR {{state}} Recovery: {{possible | not possible}} Recommendation: {{preserve unless current authority clearly calls for deletion}}. Type `discard {{candidate-id}}` to confirm.Stop. "yes", "go ahead", "get rid of it", a numbered choice → nothing is touched.
Only after that exact token: close or delete the listed task-owned resources, and nothing else.
Common mistakes
- Assuming the base/ref is current, tidying commits, or force-pushing without authority.
- Merging directly into the base before testing the integrated result.
- Writing branch-state bookkeeping into the candidate being finished.
- Treating PR creation, ownership-looking paths, praise, or "get rid of it" as cleanup, integration, or discard authority.