ce-clean-gone-branches

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Clean 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-gone
scripts/clean-gone
The script runs
git fetch --prune
first, then parses
git branch -vv
for branches marked
: gone]
.
If the script outputs
__NONE__
, report that no stale branches were found and stop.
运行发现脚本以获取最新的远程状态并识别已失效分支:
bash
bash scripts/clean-gone
scripts/clean-gone
该脚本会先运行
git fetch --prune
,然后解析
git 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:
AskUserQuestion
in Claude Code (call
ToolSearch
with
select:AskUserQuestion
first if its schema isn't loaded),
request_user_input
in Codex,
ask_user
in Gemini,
ask_user
in Pi (requires the
pi-ask-user
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.
This 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中使用
AskUserQuestion
(如果未加载其schema,需先调用
ToolSearch
并指定
select:AskUserQuestion
),在Codex中使用
request_user_input
,在Gemini中使用
ask_user
,在Pi中使用
ask_user
(需要
pi-ask-user
扩展)。仅当工具集中没有阻塞式工具或调用出错时(例如Codex编辑模式),才回退到仅在聊天中展示列表——不能因为需要加载schema就跳过提问。绝对不能静默跳过该确认步骤。
此为针对整个列表的是/否决策——不提供多选或单分支选择。

Step 3: Delete confirmed branches

步骤3:删除已确认的分支

If the user confirms, delete each branch. For each branch:
  1. Check if it has an associated worktree (
    git worktree list | grep "\\[$branch\\]"
    )
  2. If a worktree exists and is not the main repo root, remove it first:
    git worktree remove --force "$worktree_path"
  3. 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.
如果用户确认,删除每个分支。对于每个分支:
  1. 检查是否有关联的工作区(
    git worktree list | grep "\\[$branch\\]"
  2. 如果存在关联工作区且并非主仓库根目录,先移除该工作区:
    git worktree remove --force "$worktree_path"
  3. 删除分支:
    git branch -D "$branch"
逐步报告结果:
已移除工作区:.worktrees/feature/old-thing
已删除分支:feature/old-thing
已删除分支:bugfix/resolved-issue
已删除分支:experiment/abandoned

已清理3个分支。
如果用户拒绝,则确认并停止操作,不删除任何内容。