finishing-a-development-branch

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

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

步骤1:验证测试

Before presenting options, verify tests pass:
bash
undefined
在提供选项之前,先确认测试通过:
bash
undefined

Run project's test suite

运行项目测试套件

npm test / cargo test / pytest / go test ./...

**If tests fail:**
Tests failing (<N> failures). Must fix before completing:
[Show failures]
Cannot proceed with merge/PR until tests pass.

Stop. Don't proceed to Step 2.

**If tests pass:** Continue to Step 2.
npm test / cargo test / pytest / go test ./...

**如果测试失败:**
测试失败(<N> 个失败项)。完成前必须修复:
[显示失败内容]
在测试通过前,无法进行合并/PR操作。

停止操作,不要进入步骤2。

**如果测试通过:** 继续步骤2。

Step 2: Determine Base Branch

步骤2:确定基准分支

bash
undefined
bash
undefined

Try common base branches

尝试常见的基准分支

git merge-base HEAD main 2>/dev/null || git merge-base HEAD master 2>/dev/null

Or ask: "This branch split from main - is that correct?"
git merge-base HEAD main 2>/dev/null || git merge-base HEAD master 2>/dev/null

或者询问:"此分支从main分支拆分而来,是否正确?"

Step 3: Present Options

步骤3:提供选项

Present exactly these 4 options:
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?
Don't add explanation - keep options concise.
仅提供以下4个选项:
开发已完成。你想要执行什么操作?

1. 本地合并回<基准分支>
2. 推送并创建Pull Request(拉取请求)
3. 保留分支不变(我稍后处理)
4. 丢弃此工作成果

请选择选项?
不要添加解释 - 保持选项简洁。

Step 4: Execute Choice

步骤4:执行所选操作

Option 1: Merge Locally

选项1:本地合并

bash
undefined
bash
undefined

Switch to base branch

切换到基准分支

git checkout <base-branch>
git checkout <base-branch>

Pull latest

拉取最新代码

git pull
git pull

Merge feature branch

合并功能分支

git merge <feature-branch>
git merge <feature-branch>

Verify tests on merged result

验证合并后的测试结果

<test command>
<test command>

If tests pass

如果测试通过

git branch -d <feature-branch>

Then: Cleanup worktree (Step 5)
git branch -d <feature-branch>

然后:清理工作树(步骤5)

Option 2: Push and Create PR

选项2:推送并创建PR

bash
undefined
bash
undefined

Push branch

推送分支

git push -u origin <feature-branch>
git push -u origin <feature-branch>

Create PR

创建PR

gh pr create --title "<title>" --body "$(cat <<'EOF'
gh pr create --title "<title>" --body "$(cat <<'EOF'

Summary

摘要

<2-3 bullets of what changed>
<2-3条变更内容要点>

Test Plan

测试计划

  • <verification steps> EOF )"

Then: Cleanup worktree (Step 5)
  • <验证步骤> EOF )"

然后:清理工作树(步骤5)

Option 3: Keep As-Is

选项3:保留不变

Report: "Keeping branch <name>. Worktree preserved at <path>."
Don't cleanup worktree.
报告:"保留分支<名称>。工作树已保存在<路径>。"
不要清理工作树。

Option 4: Discard

选项4:丢弃

Confirm first:
This will permanently delete:
- Branch <name>
- All commits: <commit-list>
- Worktree at <path>

Type 'discard' to confirm.
Wait for exact confirmation.
If confirmed:
bash
git checkout <base-branch>
git branch -D <feature-branch>
Then: Cleanup worktree (Step 5)
先确认:
此操作将永久删除:
- 分支<名称>
- 所有提交:<提交列表>
- 工作树在<路径>

输入'discard'确认。
等待确切的确认。
如果确认:
bash
git checkout <base-branch>
git branch -D <feature-branch>
然后:清理工作树(步骤5)

Step 5: Cleanup Worktree

步骤5:清理工作树

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 worktree.
对于选项1、2、4:
检查是否在工作树中:
bash
git worktree list | grep $(git branch --show-current)
如果存在:
bash
git worktree remove <worktree-path>
对于选项3: 保留工作树。

Quick Reference

快速参考

OptionMergePushKeep WorktreeCleanup Branch
1. Merge locally--
2. Create PR--
3. Keep as-is---
4. Discard---✓ (force)
选项合并推送保留工作树清理分支
1. 本地合并--
2. 创建PR--
3. 保留不变---
4. 丢弃---✓(强制)

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
跳过测试验证
  • 问题: 合并有问题的代码,创建失败的PR
  • 解决方法: 在提供选项前始终验证测试
开放式问题
  • 问题: "我接下来该做什么?" → 表述模糊
  • 解决方法: 仅提供4个结构化选项
自动清理工作树
  • 问题: 在可能需要工作树时删除它(选项2、3)
  • 解决方法: 仅对选项1和4进行清理
丢弃时未确认
  • 问题: 意外删除工作成果
  • 解决方法: 要求输入'discard'进行确认

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
绝对不要:
  • 测试失败时继续操作
  • 未验证合并结果的测试就进行合并
  • 未确认就删除工作成果
  • 未明确请求就强制推送
始终要:
  • 在提供选项前验证测试
  • 仅提供4个选项
  • 对选项4要求输入确认
  • 仅对选项1和4清理工作树

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
被以下技能调用:
  • subagent-driven-development(步骤7)- 所有任务完成后
  • executing-plans(步骤5)- 所有批次完成后
搭配使用:
  • using-git-worktrees - 清理由该技能创建的工作树