完成开发分支
概述
通过展示清晰的选项并处理选定的工作流,指导开发工作的完成。
核心原则: 验证测试 → 展示选项 → 执行选择 → 清理。
开始时宣布: "我正在使用 finishing-a-development-branch 技能来完成这项工作。"
流程
步骤 1:验证测试
展示选项前,先验证测试通过:
# Run project's test suite
npm test / cargo test / pytest / go test ./...
如果测试失败:
Tests failing (<N> failures). Must fix before completing:
[Show failures]
Cannot proceed with merge/PR until tests pass.
停止。不要进入步骤 2。
如果测试通过: 继续步骤 2。
步骤 2:确定基础分支
# Try common base branches
git merge-base HEAD main 2>/dev/null || git merge-base HEAD master 2>/dev/null
或询问:"此分支从 main 分出 - 正确吗?"
步骤 3:展示选项
展示这 4 个选项:
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:本地合并
# Switch to base branch
git checkout <base-branch>
# Pull latest
git pull
# Merge feature branch
git merge <feature-branch>
# Verify tests on merged result
<test command>
# If tests pass
git branch -d <feature-branch>
然后:清理 worktree(步骤 5)
选项 2:推送并创建 PR
# Push branch
git push -u origin <feature-branch>
# Create PR
gh pr create --title "<title>" --body "$(cat <<'EOF'
## Summary
<2-3 bullets of what changed>
## Test Plan
- [ ] <verification steps>
EOF
)"
然后:清理 worktree(步骤 5)
选项 3:保持原状
报告:"保留分支 。Worktree 保留在 。"
不要清理 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>
然后:清理 worktree(步骤 5)
步骤 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
- 修复: 展示选项前始终验证测试
开放式提问
- 问题: "接下来我该做什么?" → 含糊不清
- 修复: 展示确切的 4 个结构化选项
自动清理 worktree
- 问题: 在可能需要时删除 worktree(选项 2、3)
- 修复: 仅对选项 1 和 4 清理
丢弃时无确认
- 问题: 意外删除工作
- 修复: 要求输入 "discard" 确认
危险信号
绝不:
- 测试失败时继续
- 未验证合并结果的测试就合并
- 未经确认删除工作
- 未经明确请求强制推送
始终:
- 展示选项前验证测试
- 展示确切的 4 个选项
- 选项 4 获取输入确认
- 仅对选项 1 和 4 清理 worktree
集成
被调用者:
- subagent-driven-development(步骤 7)- 所有任务完成后
- executing-plans(步骤 5)- 所有批次完成后
配对技能:
- using-git-worktrees - 清理该技能创建的 worktree
使用时机
本技能适用于执行概述中描述的工作流或操作。
限制
- 仅当任务明确匹配上述范围时使用本技能。
- 不要将输出视为环境特定验证、测试或专家审查的替代品。
- 如果缺少所需输入、权限、安全边界或成功标准,停止并请求澄清。