Finish Development Branch
Overview
Guide the conclusion of development work by providing clear options and executing the selected workflow.
Core Principles: Verify Tests → Present Options → Execute Selection → Cleanup.
Announce at start: "I'm using the finishing-a-development-branch skill to wrap up this work."
Process
Step 1: Verify Tests
Before presenting options, verify that tests pass:
bash
# 运行项目的测试套件
npm test / cargo test / pytest / go test ./...
If tests fail:
Tests failed (<N> failures). Must fix before proceeding:
[Show failure details]
Cannot merge/PR until tests pass.
Stop. Do not proceed to Step 2.
If tests pass: Proceed to Step 2.
Step 2: Identify Base Branch
bash
# 尝试常见的基础分支
git merge-base HEAD main 2>/dev/null || git merge-base HEAD master 2>/dev/null
Or ask: "This branch was created from main — is that correct?"
Step 3: Present Options
Present the following 4 options:
Implementation is complete. What would you like to do?
1. Merge back to <base-branch> locally
2. Push and create a Pull Request
3. Keep the branch as-is (I'll handle it later)
4. Discard this work
Which option?
Do not add explanations - keep options concise.
Step 4: Execute Selection
Option 1: Local Merge
bash
# 切换到基础分支
git checkout <base-branch>
# 拉取最新代码
git pull
# 合并功能分支
git merge <feature-branch>
# 在合并结果上验证测试
<test command>
# 如果测试通过
git branch -d <feature-branch>
Then: Clean up worktree (Step 5)
Option 2: Push and Create PR
bash
# 推送分支
git push -u origin <feature-branch>
# 创建 PR
gh pr create --title "<title>" --body "$(cat <<'EOF'
## Summary
<2-3 key change points>
## Test Plan
- [ ] <Verification steps>
EOF
)"
Then: Clean up worktree (Step 5)
Option 3: Keep As-Is
Report: "Branch <name> is retained. Worktree remains at <path>."
Do not clean up the worktree.
Option 4: Discard
Confirm first:
This will permanently delete:
- Branch <name>
- All commits: <commit-list>
- Worktree <path>
Enter 'discard' to confirm.
Wait for exact confirmation.
After confirmation:
bash
git checkout <base-branch>
git branch -D <feature-branch>
Then: Clean up worktree (Step 5)
Step 5: Clean Up Worktree
For Options 1, 2, 4:
Check if in worktree:
bash
git worktree list | grep $(git branch --show-current)
If yes:
bash
git worktree remove <worktree-path>
For Option 3: Keep the worktree.
Quick Reference
| Option | Merge | Push | Keep Worktree | Clean Up Branch |
|---|
| 1. Local Merge | ✓ | - | - | ✓ |
| 2. Create PR | - | ✓ | ✓ | - |
| 3. Keep As-Is | - | - | ✓ | - |
| 4. Discard | - | - | - | ✓ (forced) |
Common Mistakes
Skip Test Verification
- Problem: Merge broken code, create failing PRs
- Fix: Always verify tests before presenting options
Open-Ended Questions
- Problem: "What to do next?" → Ambiguity
- Fix: Precisely present the 4 structured options
Auto-Clean Worktree
- Problem: Delete worktree when it might still be needed (Options 2, 3)
- Fix: Only clean for Options 1 and 4
Discard Without Confirmation
- Problem: Accidentally delete work results
- Fix: Require input of "discard" for confirmation
Red Lines
Never:
- Proceed when tests fail
- Merge without verifying test results
- Delete work results without confirmation
- Force push without explicit request
Always:
- Verify tests before presenting options
- Precisely present the 4 options
- Require confirmation input for Option 4
- Only clean worktree for Options 1 and 4
Integration
Called by the following skills:
- subagent-driven-development (Step 7) - After all tasks are completed
- executing-plans (Step 5) - After all batches are completed
Used with:
- using-git-worktrees - Clean up worktrees created by this skill