skills/finishing-branch/SKILL.md
Use when all epic tasks show completed, when ready to integrate after review approval, when choosing between merge / PR / keep / discard for a branch, when tests need final verification before integration, or when a merge produced conflicts that require re-testing. User phrases like "ready to merge", "open a PR", "done with this branch", "ship it".
npx skillsauth add joshsymonds/gambit finishing-branchInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Complete development work by verifying readiness, presenting integration options, and executing the user's choice. Handles merge, PR creation, keeping work, or discarding — with appropriate safety gates for each.
Core principle: Verify everything passes → Present options → Execute choice → Clean up only what should be cleaned up.
Announce at start: "I'm using gambit:finishing-branch to complete this work."
LOW FREEDOM — Follow the process exactly. Never skip test verification. Never discard without typed confirmation. Always use AskUserQuestion for options.
| Step | Action | STOP If |
|------|--------|---------|
| 1. Verify Tasks | TaskList — all must be "completed" | Any task incomplete |
| 2. Verify Tests | Run full test suite (skip if review just ran it) | Any test fails |
| 3. Base Branch | Detect via git merge-base | Can't determine base |
| 4. Present Options | AskUserQuestion with 4 choices | No response |
| 5. Execute Choice | Merge / PR / Keep / Discard | Git command fails |
| 6. Cleanup | Remove worktree if applicable | Only for merge/discard |
Iron Law: Tests must be known-green BEFORE presenting options — either freshly run here (standalone invocation) or verified by gambit:review at its handoff (chained invocation). Never present options without recent green evidence.
gambit:review approves the implementationDon't use when:
gambit:executing-plansgambit:review firstgambit:brainstormingRun TaskList. All tasks must show status="completed".
If tasks still open — STOP:
Cannot finish: N tasks still open:
- [task-id]: Task Name (status: in_progress)
- [task-id]: Task Name (status: pending)
Complete all tasks before finishing.
If all complete: Read the epic with TaskGet and verify all success criteria are met.
Skip this step if invoked by gambit:review. Review's handoff guarantees tests are green (either freshly run in its Step 7 after implementing improvements, or already green since review began and no code changed). Re-running here is pure redundancy. Trust review's handoff announcement and go to Step 3.
Run the full suite only when invoked standalone (user ran /gambit:finishing-branch directly without a prior review, or invoked from any path other than review's approval gate). Detect the test command from project files (go.mod → go test ./..., package.json → npm test, Cargo.toml → cargo test, pyproject.toml → pytest, Makefile → make test).
git merge-base HEAD main 2>/dev/null || git merge-base HEAD master 2>/dev/null
If this fails, ask the user what base branch to use.
Use AskUserQuestion — do not print options as text.
AskUserQuestion
questions:
- question: "All tasks complete, tests passing. How should we integrate?"
header: "Integration"
options:
- label: "Merge locally"
description: "Merge to <base-branch>, delete feature branch"
- label: "Create Pull Request"
description: "Push and create PR for review"
- label: "Keep as-is"
description: "Leave branch and worktree, handle later"
- label: "Discard"
description: "Delete all work (requires typed confirmation)"
multiSelect: false
STOP. Wait for user response. Do not add recommendations, defaults, or explanations.
The 4 options above are fixed. Never modify, reorder, add variants (like "merge and push"), or remove any. The "Never push main" rule means pushing is never offered — user pushes manually after merge.
git checkout <base-branch>
git pull
git merge <feature-branch>
Run tests on merged result — if tests fail, present sub-options:
git merge --abort)STOP and wait for user choice.
git branch -d <feature-branch> (safe delete)
Go to Step 6
Do NOT push to remote. User pushes when ready.
git push -u origin <feature-branch>TaskGet for PR contentgh pr create --title "feat: <epic-name>" --body "$(cat <<'EOF'
## Summary
<2-3 bullets from epic requirements>
## Tasks Completed
<list from TaskList>
## Test Plan
- [ ] All tests passing
- [ ] <verification steps from epic>
EOF
)"
DONE — do NOT go to Step 6. Branch and worktree (if any) are preserved for PR feedback.
Report: "Keeping branch <name>." If worktree exists, add: "Worktree preserved at <path>."
DONE — do NOT go to Step 6.
git log --oneline <base-branch>..HEAD
This will permanently delete:
- Branch <name>
- All N commits listed above
- Worktree at <path> (if applicable)
Type 'discard' to confirm.
STOP. Wait for exact text "discard". Anything else → clarify, do not proceed.
git checkout <base-branch>git branch -D <feature-branch>Only runs for Options 1 and 4. Options 2 and 3 skip this entirely.
Check if a worktree exists for this branch:
git worktree list
git worktree remove <path>Report cleanup results.
Step 1: TaskList → all 4 tasks completed
Step 2: npm test → 127 tests passed
Step 3: git merge-base HEAD main → abc123
Step 4: [AskUserQuestion with 4 options]
User selects: Merge locally
Step 5: git checkout main
git pull
git merge feature-auth
npm test → 127 tests passed (verify merged result)
git branch -d feature-auth
Step 6: git worktree remove .worktrees/auth
Done. Feature merged to main.
Step 1: Tasks complete
Step 2: SKIPPED ← WRONG: tests might fail
Step 4: User selects PR
Step 5: git push, gh pr create
git worktree remove ← WRONG: PR needs worktree
# Merged broken code. Lost worktree for PR feedback.
git log --oneline main..HEAD
→ a1b2c3d Add OAuth
→ d4e5f6g Add rate limiting
"This will permanently delete branch and 2 commits.
Type 'discard' to confirm."
User: "discard"
git checkout main && git branch -D feature-experimental
git worktree remove .worktrees/experimental
Common rationalizations (all mean STOP, follow the process):
| Excuse | Reality | |--------|---------| | "Tests passed earlier" | RUN THEM NOW unless review just handed off with a green-tests guarantee — code might have changed | | "User obviously wants to merge" | PRESENT ALL 4 OPTIONS — let them choose | | "User said discard" | GET TYPED CONFIRMATION — "discard" exactly | | "PR done, cleanup worktree" | KEEP IT — PR will need updates | | "Tasks are mostly done" | ALL must be complete — no exceptions |
TaskList)AskUserQuestionCalled by:
/gambit:finishing-branchgambit:review (after approval — the normal workflow path)gambit:executing-plans → gambit:review completesCalls:
gh CLI (PR creation)git commands (merge, branch, worktree)Pairs with:
gambit:using-worktrees — cleans up worktree created by that skilltesting
Use when creating a new skill, modifying an existing skill, writing or rewriting a SKILL.md file, auditing a skill's description for discoverability, or when user mentions "create a skill", "write a skill", "new skill", "modify skill", "improve skill", "edit the skill".
development
Use before any completion claim, success statement, or marking a task done. Triggers when about to say "Great!", "Perfect!", "Done", "All set", "Ready to commit", before creating a PR, before moving to the next task, or when code has changed since the last test run.
data-ai
Use when starting an isolated feature branch, when working on multiple features simultaneously, when experimenting without affecting the main workspace, or when a clean workspace is needed before beginning implementation. User phrases like "start a new branch", "set up a worktree", "isolated workspace", "work on feature X separately".
development
Use at the start of every session before any response or action. Also invoke whenever uncertain which gambit skill applies, when about to implement / debug / refactor / test / plan / brainstorm, or when a user request could match any gambit skill even at 1% probability.