SuperAPI AI Directory

finishing-a-development-branch

Coding & development

View repository

Updated 10-16 09:44

About this skill

Finishing a Development Branch

Overview

Guide the completion of development work by providing clear options and executing the 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."

Process

Step 1: Verify Tests

Before presenting options, verify tests pass:

# 运行项目的测试套件
npm test / cargo test / pytest / go test ./...

If tests fail:

测试失败(<N> 个失败)。必须先修复才能继续:

[显示失败信息]

在测试通过之前无法进行合并/PR。

Stop. Do not proceed to Step 2.

If tests pass: Proceed to Step 2.

Step 2: Determine Base Branch

# 尝试常见的基础分支
git merge-base HEAD main 2>/dev/null || git merge-base HEAD master 2>/dev/null

Or ask: "This branch was split from main—right?"

Step 3: Present Options

Present the following 4 options:

实现已完成。你想怎么做?

1. 在本地合并回 <base-branch>
2. 推送并创建 Pull Request
3. 保持分支现状(我稍后处理)
4. 丢弃这项工作

选哪个?

Do not add explanations - Keep options concise.

Step 4: Execute Choice

Option 1: Merge Locally

# 切换到基础分支
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

# 推送分支
git push -u origin <feature-branch>

# 创建 PR
gh pr create --title "<title>" --body "$(cat <<'EOF'
## 摘要
<2-3 条变更要点>

## 测试计划
- [ ] <验证步骤>
EOF
)"

Then: Clean up worktree (Step 5)

Option 3: Keep As Is

Report: "Kept branch . Worktree kept at ."

Do not clean up the worktree.

Option 4: Discard

Confirm first:

这将永久删除:
- 分支 <name>
- 所有提交:<commit-list>
- 工作树 <path>

输入 'discard' 确认。

Wait for the exact confirmation.

After confirmation:

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 a worktree:

git worktree list | grep $(git branch --show-current)

If yes:

git worktree remove <worktree-path>

For option 3: Keep the worktree.

Quick Reference

Option Merge Push Keep Worktree Clean Up Branch
1. Merge Locally ✓ - - ✓
2. Create PR - ✓ ✓ -
3. Keep As Is - - ✓ -
4. Discard - - - ✓ (mandatory)

Common Mistakes

Skipping test verification

  • Problem: Merging broken code, creating failed PRs
  • Fix: Always verify tests before offering options

Open-ended questions

  • Problem: "What should I do next?" → vague
  • Fix: Present exactly 4 structured options

Automatically cleaning up the worktree

  • Problem: Deleted while the worktree might still be needed (options 2, 3)
  • Fix: Only clean up for options 1 and 4

Not confirming when discarding

  • Problem: Accidentally deleting work results
  • Fix: Require typing "discard" to confirm

Red Lines

Never:

  • Continue when tests fail
  • Merge without verifying test results first
  • Delete work results without confirmation
  • Force push without explicit request

Always:

  • Verify tests before offering options
  • Show exactly 4 options
  • Option 4 requires typing confirmation
  • Only clean up the 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