Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Guides completion of a development branch by verifying tests then offering structured choices: merge, PR, keep, or discard.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
SKILL.md
1---2name: finishing-a-development-branch3description: Use when implementation is complete, all tests pass, and you need to decide how to integrate the work - guides completion of development work by presenting structured options for merge, PR, or cleanup4---56# Finishing a Development Branch78## Overview910Guide completion of development work by presenting clear options and handling chosen workflow.1112**Core principle:** Verify tests → Detect environment → Present options → Execute choice → Clean up.1314**Announce at start:** "I'm using the finishing-a-development-branch skill to complete this work."1516## The Process1718### Step 1: Verify Tests1920**Before presenting options, verify tests pass:**2122```bash23# Run project's test suite24npm test / cargo test / pytest / go test ./...25```2627**If tests fail:**28```29Tests failing (<N> failures). Must fix before completing:3031[Show failures]3233Cannot proceed with merge/PR until tests pass.34```3536Stop. Don't proceed to Step 2.3738**If tests pass:** Continue to Step 2.3940### Step 2: Detect Environment4142**Determine workspace state before presenting options:**4344```bash45GIT_DIR=$(cd "$(git rev-parse --git-dir)" 2>/dev/null && pwd -P)46GIT_COMMON=$(cd "$(git rev-parse --git-common-dir)" 2>/dev/null && pwd -P)47```4849This determines which menu to show and how cleanup works:5051| State | Menu | Cleanup |52|-------|------|---------|53| `GIT_DIR == GIT_COMMON` (normal repo) | Standard 4 options | No worktree to clean up |54| `GIT_DIR != GIT_COMMON`, named branch | Standard 4 options | Provenance-based (see Step 6) |55| `GIT_DIR != GIT_COMMON`, detached HEAD | Reduced 3 options (no merge) | No cleanup (externally managed) |5657### Step 3: Determine Base Branch5859```bash60# Try common base branches61git merge-base HEAD main 2>/dev/null || git merge-base HEAD master 2>/dev/null62```6364Or ask: "This branch split from main - is that correct?"6566### Step 4: Present Options6768**Normal repo and named-branch worktree — present exactly these 4 options:**6970```71Implementation complete. What would you like to do?72731. Merge back to <base-branch> locally742. Push and create a Pull Request753. Keep the branch as-is (I'll handle it later)764. Discard this work7778Which option?79```8081**Detached HEAD — present exactly these 3 options:**8283```84Implementation complete. You're on a detached HEAD (externally managed workspace).85861. Push as new branch and create a Pull Request872. Keep as-is (I'll handle it later)883. Discard this work8990Which option?91```9293**Don't add explanation** - keep options concise.9495### Step 5: Execute Choice9697#### Option 1: Merge Locally9899```bash100# Get main repo root for CWD safety101MAIN_ROOT=$(git -C "$(git rev-parse --git-common-dir)/.." rev-parse --show-toplevel)102cd "$MAIN_ROOT"103104# Merge first — verify success before removing anything105git checkout <base-branch>106git pull107git merge <feature-branch>108109# Verify tests on merged result110<test command>111112# Only after merge succeeds: cleanup worktree (Step 6), then delete branch113```114115Then: Cleanup worktree (Step 6), then delete branch:116117```bash118git branch -d <feature-branch>119```120121#### Option 2: Push and Create PR122123```bash124# Push branch125git push -u origin <feature-branch>126127# Create PR128gh pr create --title "<title>" --body "$(cat <<'EOF'129## Summary130<2-3 bullets of what changed>131132## Test Plan133- [ ] <verification steps>134EOF135)"136```137138**Do NOT clean up worktree** — user needs it alive to iterate on PR feedback.139140#### Option 3: Keep As-Is141142Report: "Keeping branch <name>. Worktree preserved at <path>."143144**Don't cleanup worktree.**145146#### Option 4: Discard147148**Confirm first:**149```150This will permanently delete:151- Branch <name>152- All commits: <commit-list>153- Worktree at <path>154155Type 'discard' to confirm.156```157158Wait for exact confirmation.159160If confirmed:161```bash162MAIN_ROOT=$(git -C "$(git rev-parse --git-common-dir)/.." rev-parse --show-toplevel)163cd "$MAIN_ROOT"164```165166Then: Cleanup worktree (Step 6), then force-delete branch:167```bash168git branch -D <feature-branch>169```170171### Step 6: Cleanup Workspace172173**Only runs for Options 1 and 4.** Options 2 and 3 always preserve the worktree.174175```bash176GIT_DIR=$(cd "$(git rev-parse --git-dir)" 2>/dev/null && pwd -P)177GIT_COMMON=$(cd "$(git rev-parse --git-common-dir)" 2>/dev/null && pwd -P)178WORKTREE_PATH=$(git rev-parse --show-toplevel)179```180181**If `GIT_DIR == GIT_COMMON`:** Normal repo, no worktree to clean up. Done.182183**If worktree path is under `.worktrees/`, `worktrees/`, or `~/.config/superpowers/worktrees/`:** Superpowers created this worktree — we own cleanup.184185```bash186MAIN_ROOT=$(git -C "$(git rev-parse --git-common-dir)/.." rev-parse --show-toplevel)187cd "$MAIN_ROOT"188git worktree remove "$WORKTREE_PATH"189git worktree prune # Self-healing: clean up any stale registrations190```191192**Otherwise:** The host environment (harness) owns this workspace. Do NOT remove it. If your platform provides a workspace-exit tool, use it. Otherwise, leave the workspace in place.193194## Quick Reference195196| Option | Merge | Push | Keep Worktree | Cleanup Branch |197|--------|-------|------|---------------|----------------|198| 1. Merge locally | yes | - | - | yes |199| 2. Create PR | - | yes | yes | - |200| 3. Keep as-is | - | - | yes | - |201| 4. Discard | - | - | - | yes (force) |202203## Common Mistakes204205**Skipping test verification**206- **Problem:** Merge broken code, create failing PR207- **Fix:** Always verify tests before offering options208209**Open-ended questions**210- **Problem:** "What should I do next?" is ambiguous211- **Fix:** Present exactly 4 structured options (or 3 for detached HEAD)212213**Cleaning up worktree for Option 2**214- **Problem:** Remove worktree user needs for PR iteration215- **Fix:** Only cleanup for Options 1 and 4216217**Deleting branch before removing worktree**218- **Problem:** `git branch -d` fails because worktree still references the branch219- **Fix:** Merge first, remove worktree, then delete branch220221**Running git worktree remove from inside the worktree**222- **Problem:** Command fails silently when CWD is inside the worktree being removed223- **Fix:** Always `cd` to main repo root before `git worktree remove`224225**Cleaning up harness-owned worktrees**226- **Problem:** Removing a worktree the harness created causes phantom state227- **Fix:** Only clean up worktrees under `.worktrees/`, `worktrees/`, or `~/.config/superpowers/worktrees/`228229**No confirmation for discard**230- **Problem:** Accidentally delete work231- **Fix:** Require typed "discard" confirmation232233## Red Flags234235**Never:**236- Proceed with failing tests237- Merge without verifying tests on result238- Delete work without confirmation239- Force-push without explicit request240- Remove a worktree before confirming merge success241- Clean up worktrees you didn't create (provenance check)242- Run `git worktree remove` from inside the worktree243244**Always:**245- Verify tests before offering options246- Detect environment before presenting menu247- Present exactly 4 options (or 3 for detached HEAD)248- Get typed confirmation for Option 4249- Clean up worktree for Options 1 & 4 only250- `cd` to main repo root before worktree removal251- Run `git worktree prune` after removal252