用途
该技能用于在开发工作完成后,引导用户选择如何整合代码。它适用于实现已完成、所有测试通过、需要决定如何整合工作的场景。技能的核心原则是:验证测试 → 呈现选项 → 执行选择 → 清理。开始时应声明:“I'm using the finishing-a-development-branch skill to complete this work.”
主要能力
技能提供一套结构化的分支收尾流程,包括:
- 验证测试是否通过;
- 确定基础分支;
- 呈现四个固定选项;
- 根据用户选择执行对应的 Git 操作;
- 清理 worktree。
使用方式
步骤 1:验证测试
在呈现选项之前,先运行项目测试套件:
npm test / cargo test / pytest / go test ./...
如果测试失败,应显示失败信息并停止,不得进入步骤 2:
Tests failing (<N> failures). Must fix before completing:
[Show failures]
Cannot proceed with merge/PR until tests pass.
如果测试通过,继续步骤 2。
步骤 2:确定基础分支
尝试常见基础分支:
git merge-base HEAD main 2>/dev/null || git merge-base HEAD master 2>/dev/null
或询问:“This branch split from main - is that correct?”
步骤 3:呈现选项
呈现以下四个选项:
Implementation 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?
不要添加解释,保持选项简洁。
步骤 4:执行选择
选项 1:本地合并
git checkout <base-branch>
git pull
git merge <feature-branch>
<test command>
git branch -d <feature-branch>
然后执行步骤 5 清理 worktree。
选项 2:推送并创建 PR
git push -u origin <feature-branch>
gh pr create --title "<title>" --body "$(cat <<'EOF'
## Summary
<2-3 bullets of what changed>
## Test Plan
- [ ] <verification steps>
EOF
)"
然后执行步骤 5 清理 worktree。
选项 3:保持原样
报告:“Keeping branch . Worktree preserved at .” 不要清理 worktree。
选项 4:丢弃
先确认:
This will permanently delete:
- Branch <name>
- All commits: <commit-list>
- Worktree at <path>
Type 'discard' to confirm.
等待精确确认。确认后执行:
git checkout <base-branch>
git branch -D <feature-branch>
然后执行步骤 5 清理 worktree。
步骤 5:清理 worktree
对于选项 1、2、4:
检查是否在 worktree 中:
git worktree list | grep $(git branch --show-current)
如果是,执行:
git worktree remove <worktree-path>
对于选项 3:保留 worktree。
快速参考
| 选项 | 合并 | 推送 | 保留 Worktree | 清理分支 |
|---|---|---|---|---|
| 1. 本地合并 | ✓ | - | - | ✓ |
| 2. 创建 PR | - | ✓ | ✓ | - |
| 3. 保持原样 | - | - | ✓ | - |
| 4. 丢弃 | - | - | - | ✓(强制) |
常见错误
- 跳过测试验证:问题在于可能合并损坏代码或创建失败的 PR;修复方法是始终在提供选项前验证测试。
- 开放式问题:问题在于“What should I do next?”会产生歧义;修复方法是呈现恰好四个结构化选项。
- 自动清理 worktree:问题在于可能在需要时移除 worktree(选项 2、3);修复方法是仅对选项 1 和 4 进行清理。
- 丢弃时无确认:问题在于可能意外删除工作;修复方法是要求输入“discard”确认。
红线
绝不:
- 在测试失败时继续;
- 未验证结果测试就合并;
- 未经确认删除工作;
- 未经明确请求强制推送。
始终:
- 在提供选项前验证测试;
- 呈现恰好四个选项;
- 对选项 4 获取输入确认;
- 仅对选项 1 和 4 清理 worktree。
集成
被以下技能调用:
- subagent-driven-development(步骤 7)——所有任务完成后;
- executing-plans(步骤 5)——所有批次完成后。
与以下技能配对:
- using-git-worktrees——清理该技能创建的 worktree。