|
| 1 | +--- |
| 2 | +name: finishing-a-development-branch |
| 3 | +description: 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 cleanup |
| 4 | +--- |
| 5 | + |
| 6 | +# Finishing a Development Branch |
| 7 | + |
| 8 | +## Overview |
| 9 | + |
| 10 | +Guide completion of development work by presenting clear options and handling chosen workflow. |
| 11 | + |
| 12 | +**Core principle:** Verify tests → Present options → Execute choice → Clean up. |
| 13 | + |
| 14 | +**Announce at start:** "I'm using the finishing-a-development-branch skill to complete this work." |
| 15 | + |
| 16 | +## The Process |
| 17 | + |
| 18 | +### Step 1: Verify Tests |
| 19 | + |
| 20 | +**Before presenting options, verify tests pass:** |
| 21 | + |
| 22 | +```bash |
| 23 | +# Run project's test suite |
| 24 | +npm test / cargo test / pytest / go test ./... |
| 25 | +``` |
| 26 | + |
| 27 | +**If tests fail:** |
| 28 | +``` |
| 29 | +Tests failing (<N> failures). Must fix before completing: |
| 30 | +
|
| 31 | +[Show failures] |
| 32 | +
|
| 33 | +Cannot proceed with merge/PR until tests pass. |
| 34 | +``` |
| 35 | + |
| 36 | +Stop. Don't proceed to Step 2. |
| 37 | + |
| 38 | +**If tests pass:** Continue to Step 2. |
| 39 | + |
| 40 | +### Step 2: Determine Base Branch |
| 41 | + |
| 42 | +```bash |
| 43 | +# Try common base branches |
| 44 | +git merge-base HEAD main 2>/dev/null || git merge-base HEAD master 2>/dev/null |
| 45 | +``` |
| 46 | + |
| 47 | +Or ask: "This branch split from main - is that correct?" |
| 48 | + |
| 49 | +### Step 3: Present Options |
| 50 | + |
| 51 | +Present exactly these 4 options: |
| 52 | + |
| 53 | +``` |
| 54 | +Implementation complete. What would you like to do? |
| 55 | +
|
| 56 | +1. Merge back to <base-branch> locally |
| 57 | +2. Push and create a Pull Request |
| 58 | +3. Keep the branch as-is (I'll handle it later) |
| 59 | +4. Discard this work |
| 60 | +
|
| 61 | +Which option? |
| 62 | +``` |
| 63 | + |
| 64 | +**Don't add explanation** - keep options concise. |
| 65 | + |
| 66 | +### Step 4: Execute Choice |
| 67 | + |
| 68 | +#### Option 1: Merge Locally |
| 69 | + |
| 70 | +```bash |
| 71 | +# Switch to base branch |
| 72 | +git checkout <base-branch> |
| 73 | + |
| 74 | +# Pull latest |
| 75 | +git pull |
| 76 | + |
| 77 | +# Merge feature branch |
| 78 | +git merge <feature-branch> |
| 79 | + |
| 80 | +# Verify tests on merged result |
| 81 | +<test command> |
| 82 | + |
| 83 | +# If tests pass |
| 84 | +git branch -d <feature-branch> |
| 85 | +``` |
| 86 | + |
| 87 | +Then: Cleanup worktree (Step 5) |
| 88 | + |
| 89 | +#### Option 2: Push and Create PR |
| 90 | + |
| 91 | +```bash |
| 92 | +# Push branch |
| 93 | +git push -u origin <feature-branch> |
| 94 | + |
| 95 | +# Create PR |
| 96 | +gh pr create --title "<title>" --body "$(cat <<'EOF' |
| 97 | +## Summary |
| 98 | +<2-3 bullets of what changed> |
| 99 | +
|
| 100 | +## Test Plan |
| 101 | +- [ ] <verification steps> |
| 102 | +EOF |
| 103 | +)" |
| 104 | +``` |
| 105 | + |
| 106 | +Then: Cleanup worktree (Step 5) |
| 107 | + |
| 108 | +#### Option 3: Keep As-Is |
| 109 | + |
| 110 | +Report: "Keeping branch <name>. Worktree preserved at <path>." |
| 111 | + |
| 112 | +**Don't cleanup worktree.** |
| 113 | + |
| 114 | +#### Option 4: Discard |
| 115 | + |
| 116 | +**Confirm first:** |
| 117 | +``` |
| 118 | +This will permanently delete: |
| 119 | +- Branch <name> |
| 120 | +- All commits: <commit-list> |
| 121 | +- Worktree at <path> |
| 122 | +
|
| 123 | +Type 'discard' to confirm. |
| 124 | +``` |
| 125 | + |
| 126 | +Wait for exact confirmation. |
| 127 | + |
| 128 | +If confirmed: |
| 129 | +```bash |
| 130 | +git checkout <base-branch> |
| 131 | +git branch -D <feature-branch> |
| 132 | +``` |
| 133 | + |
| 134 | +Then: Cleanup worktree (Step 5) |
| 135 | + |
| 136 | +### Step 5: Cleanup Worktree |
| 137 | + |
| 138 | +**For Options 1, 2, 4:** |
| 139 | + |
| 140 | +Check if in worktree: |
| 141 | +```bash |
| 142 | +git worktree list | grep $(git branch --show-current) |
| 143 | +``` |
| 144 | + |
| 145 | +If yes: |
| 146 | +```bash |
| 147 | +git worktree remove <worktree-path> |
| 148 | +``` |
| 149 | + |
| 150 | +**For Option 3:** Keep worktree. |
| 151 | + |
| 152 | +## Quick Reference |
| 153 | + |
| 154 | +| Option | Merge | Push | Keep Worktree | Cleanup Branch | |
| 155 | +|--------|-------|------|---------------|----------------| |
| 156 | +| 1. Merge locally | ✓ | - | - | ✓ | |
| 157 | +| 2. Create PR | - | ✓ | ✓ | - | |
| 158 | +| 3. Keep as-is | - | - | ✓ | - | |
| 159 | +| 4. Discard | - | - | - | ✓ (force) | |
| 160 | + |
| 161 | +## Common Mistakes |
| 162 | + |
| 163 | +**Skipping test verification** |
| 164 | +- **Problem:** Merge broken code, create failing PR |
| 165 | +- **Fix:** Always verify tests before offering options |
| 166 | + |
| 167 | +**Open-ended questions** |
| 168 | +- **Problem:** "What should I do next?" → ambiguous |
| 169 | +- **Fix:** Present exactly 4 structured options |
| 170 | + |
| 171 | +**Automatic worktree cleanup** |
| 172 | +- **Problem:** Remove worktree when might need it (Option 2, 3) |
| 173 | +- **Fix:** Only cleanup for Options 1 and 4 |
| 174 | + |
| 175 | +**No confirmation for discard** |
| 176 | +- **Problem:** Accidentally delete work |
| 177 | +- **Fix:** Require typed "discard" confirmation |
| 178 | + |
| 179 | +## Red Flags |
| 180 | + |
| 181 | +**Never:** |
| 182 | +- Proceed with failing tests |
| 183 | +- Merge without verifying tests on result |
| 184 | +- Delete work without confirmation |
| 185 | +- Force-push without explicit request |
| 186 | + |
| 187 | +**Always:** |
| 188 | +- Verify tests before offering options |
| 189 | +- Present exactly 4 options |
| 190 | +- Get typed confirmation for Option 4 |
| 191 | +- Clean up worktree for Options 1 & 4 only |
| 192 | + |
| 193 | +## Integration |
| 194 | + |
| 195 | +**Called by:** |
| 196 | +- **subagent-driven-development** (Step 7) - After all tasks complete |
| 197 | +- **executing-plans** (Step 5) - After all batches complete |
| 198 | + |
| 199 | +**Pairs with:** |
| 200 | +- **using-git-worktrees** - Cleans up worktree created by that skill |
0 commit comments