Finishing a Development Branch
Overview
Guide completion of development work by presenting clear options and handling chosen workflow.
Core principle: Verify tests → Present options → Execute choice → Clean up.
Announce at start: "I'm using the finishing-a-development-branch skill to complete this work."
The Process
Step 1: Verify Tests
Before presenting options, verify tests pass:
CODEBLOCK0
If tests fail:
CODEBLOCK1
Stop. Don't proceed to Step 2.
If tests pass: Continue to Step 2.
Step 2: Determine Base Branch
CODEBLOCK2
Or ask: "This branch split from main - is that correct?"
Step 3: Present Options
Present exactly these 4 options:
CODEBLOCK3
Don't add explanation - keep options concise.
Step 4: Execute Choice
Option 1: Merge Locally
CODEBLOCK4
Then: Cleanup worktree (Step 5)
Option 2: Push and Create PR
CODEBLOCK5
Then: Cleanup worktree (Step 5)
Option 3: Keep As-Is
Report: "Keeping branch . Worktree preserved at ."
Don't cleanup worktree.
Option 4: Discard
Confirm first:
CODEBLOCK6
Wait for exact confirmation.
If confirmed:
CODEBLOCK7
Then: Cleanup worktree (Step 5)
Step 5: Cleanup Worktree
For Options 1, 2, 4:
Check if in worktree:
CODEBLOCK8
If yes:
CODEBLOCK9
For Option 3: Keep worktree.
Quick Reference
| Option | Merge | Push | Keep Worktree | Cleanup Branch |
|---|
| 1. Merge locally | ✓ | - | - | ✓ |
| 2. Create PR |
- | ✓ | ✓ | - |
| 3. Keep as-is | - | - | ✓ | - |
| 4. Discard | - | - | - | ✓ (force) |
Common Mistakes
Skipping test verification
- - Problem: Merge broken code, create failing PR
- Fix: Always verify tests before offering options
Open-ended questions
- - Problem: "What should I do next?" → ambiguous
- Fix: Present exactly 4 structured options
Automatic worktree cleanup
- - Problem: Remove worktree when might need it (Option 2, 3)
- Fix: Only cleanup for Options 1 and 4
No confirmation for discard
- - Problem: Accidentally delete work
- Fix: Require typed "discard" confirmation
Red Flags
Never:
- - Proceed with failing tests
- Merge without verifying tests on result
- Delete work without confirmation
- Force-push without explicit request
Always:
- - Verify tests before offering options
- Present exactly 4 options
- Get typed confirmation for Option 4
- Clean up worktree for Options 1 & 4 only
Integration
Called by:
- - subagent-driven-development (Step 7) - After all tasks complete
- executing-plans (Step 5) - After all batches complete
Pairs with:
- - using-git-worktrees - Cleans up worktree created by that skill
完成开发分支
概述
通过提供清晰选项并处理所选工作流程,指导开发工作的完成。
核心原则: 验证测试 → 呈现选项 → 执行选择 → 清理。
开始时声明: 我正在使用完成开发分支技能来完成此项工作。
流程
步骤 1:验证测试
在呈现选项之前,验证测试是否通过:
bash
运行项目的测试套件
npm test / cargo test / pytest / go test ./...
如果测试失败:
测试失败( 个失败)。必须在完成前修复:
[显示失败项]
在测试通过前,无法继续合并/PR操作。
停止。不要进入步骤 2。
如果测试通过: 继续执行步骤 2。
步骤 2:确定基础分支
bash
尝试常见的基础分支
git merge-base HEAD main 2>/dev/null || git merge-base HEAD master 2>/dev/null
或询问:此分支从 main 分支分出 - 是否正确?
步骤 3:呈现选项
精确呈现以下 4 个选项:
实现已完成。您希望做什么?
- 1. 合并回 <基础分支>(本地)
- 推送并创建拉取请求
- 保持分支现状(稍后自行处理)
- 放弃此项工作
选择哪个选项?
不要添加解释 - 保持选项简洁。
步骤 4:执行选择
选项 1:本地合并
bash
切换到基础分支
git checkout <基础分支>
拉取最新代码
git pull
合并功能分支
git merge <功能分支>
验证合并结果的测试
<测试命令>
如果测试通过
git branch -d <功能分支>
然后:清理工作树(步骤 5)
选项 2:推送并创建 PR
bash
推送分支
git push -u origin <功能分支>
创建 PR
gh pr create --title <标题> --body $(cat <
摘要
<2-3 条变更要点>
测试计划
EOF
)
然后:清理工作树(步骤 5)
选项 3:保持现状
报告:保留分支 <名称>。工作树保留在 <路径>。
不要清理工作树。
选项 4:放弃
先确认:
此操作将永久删除:
- - 分支 <名称>
- 所有提交:<提交列表>
- 位于 <路径> 的工作树
输入 discard 确认。
等待精确确认。
如果确认:
bash
git checkout <基础分支>
git branch -D <功能分支>
然后:清理工作树(步骤 5)
步骤 5:清理工作树
对于选项 1、2、4:
检查是否在工作树中:
bash
git worktree list | grep $(git branch --show-current)
如果是:
bash
git worktree remove <工作树路径>
对于选项 3: 保留工作树。
快速参考
| 选项 | 合并 | 推送 | 保留工作树 | 清理分支 |
|---|
| 1. 本地合并 | ✓ | - | - | ✓ |
| 2. 创建 PR |
- | ✓ | ✓ | - |
| 3. 保持现状 | - | - | ✓ | - |
| 4. 放弃 | - | - | - | ✓(强制) |
常见错误
跳过测试验证
- - 问题: 合并损坏的代码,创建失败的 PR
- 修复: 在提供选项前始终验证测试
开放式问题
- - 问题: 下一步该做什么? → 含糊不清
- 修复: 精确呈现 4 个结构化选项
自动清理工作树
- - 问题: 在可能需要时移除工作树(选项 2、3)
- 修复: 仅对选项 1 和 4 进行清理
放弃操作无确认
- - 问题: 意外删除工作
- 修复: 要求输入 discard 确认
警示标志
绝对不要:
- - 在测试失败时继续
- 未验证结果测试就进行合并
- 未经确认删除工作
- 未经明确请求强制推送
始终:
- - 在提供选项前验证测试
- 精确呈现 4 个选项
- 对选项 4 获取输入确认
- 仅对选项 1 和 4 清理工作树
集成
被调用者:
- - 子代理驱动开发(步骤 7)- 所有任务完成后
- 执行计划(步骤 5)- 所有批次完成后
配合使用:
- - 使用 Git 工作树 - 清理该技能创建的工作树