ce-clean-gone-branches
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseClean Gone Branches
清理已失效分支
Delete local branches whose remote tracking branch has been deleted, including any associated worktrees.
删除远程追踪分支已被删除的本地分支,包括所有关联的工作区。
Workflow
操作流程
Step 1: Discover gone branches
步骤1:发现已失效分支
Run the discovery script to fetch the latest remote state and identify gone branches:
bash
bash scripts/clean-gonescripts/clean-gone
The script runs first, then parses for branches marked .
git fetch --prunegit branch -vv: gone]If the script outputs , report that no stale branches were found and stop.
__NONE__运行发现脚本以获取最新的远程状态并识别已失效分支:
bash
bash scripts/clean-gonescripts/clean-gone
该脚本会先运行 ,然后解析 结果以找出标记为 的分支。
git fetch --prunegit branch -vv: gone]如果脚本输出 ,则报告未找到陈旧分支并停止操作。
__NONE__Step 2: Present branches and ask for confirmation
步骤2:展示分支并请求确认
Show the user the list of branches that will be deleted. Format as a simple list:
These local branches have been deleted from the remote:
- feature/old-thing
- bugfix/resolved-issue
- experiment/abandoned
Delete all of them? (y/n)Wait for the user's answer using the platform's blocking question tool: in Claude Code (call with first if its schema isn't loaded), in Codex, in Gemini, in Pi (requires the extension). Fall back to presenting the list in chat only when no blocking tool exists in the harness or the call errors (e.g., Codex edit modes) — not because a schema load is required. Never silently skip the question.
AskUserQuestionToolSearchselect:AskUserQuestionrequest_user_inputask_userask_userpi-ask-userThis is a yes-or-no decision on the entire list -- do not offer multi-selection or per-branch choices.
向用户展示将要删除的分支列表,格式为简单列表:
以下本地分支已从远程删除:
- feature/old-thing
- bugfix/resolved-issue
- experiment/abandoned
是否全部删除?(y/n)使用平台的阻塞式提问工具等待用户回复:在Claude Code中使用(如果未加载其schema,需先调用并指定),在Codex中使用,在Gemini中使用,在Pi中使用(需要扩展)。仅当工具集中没有阻塞式工具或调用出错时(例如Codex编辑模式),才回退到仅在聊天中展示列表——不能因为需要加载schema就跳过提问。绝对不能静默跳过该确认步骤。
AskUserQuestionToolSearchselect:AskUserQuestionrequest_user_inputask_userask_userpi-ask-user此为针对整个列表的是/否决策——不提供多选或单分支选择。
Step 3: Delete confirmed branches
步骤3:删除已确认的分支
If the user confirms, delete each branch. For each branch:
- Check if it has an associated worktree ()
git worktree list | grep "\\[$branch\\]" - If a worktree exists and is not the main repo root, remove it first:
git worktree remove --force "$worktree_path" - Delete the branch:
git branch -D "$branch"
Report results as you go:
Removed worktree: .worktrees/feature/old-thing
Deleted branch: feature/old-thing
Deleted branch: bugfix/resolved-issue
Deleted branch: experiment/abandoned
Cleaned up 3 branches.If the user declines, acknowledge and stop without deleting anything.
如果用户确认,删除每个分支。对于每个分支:
- 检查是否有关联的工作区()
git worktree list | grep "\\[$branch\\]" - 如果存在关联工作区且并非主仓库根目录,先移除该工作区:
git worktree remove --force "$worktree_path" - 删除分支:
git branch -D "$branch"
逐步报告结果:
已移除工作区:.worktrees/feature/old-thing
已删除分支:feature/old-thing
已删除分支:bugfix/resolved-issue
已删除分支:experiment/abandoned
已清理3个分支。如果用户拒绝,则确认并停止操作,不删除任何内容。