git-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]
. It uses
command git
to bypass shell aliases and RTK proxies.
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]
的分支。它使用
command git
来绕过shell别名和RTK代理。
如果脚本输出
__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 question tool (e.g.,
AskUserQuestion
in Claude Code,
request_user_input
in Codex,
ask_user
in Gemini). If no question tool is available, present the list and wait for the user's reply before proceeding.
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
、Codex中的
request_user_input
、Gemini中的
ask_user
)。如果没有可用的提问工具,则展示列表并等待用户回复后再继续。
这是针对整个列表的是/否决策——不提供多选或单分支选择。

Step 3: Delete confirmed branches

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

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

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

Important: Use
command git

重要提示:使用
command git

Always invoke git as
command git
in shell commands. This bypasses shell aliases and tools like RTK (Rust Token Killer) that proxy git commands, ensuring consistent behavior and output parsing.
在shell命令中始终以
command git
调用git。这可以绕过shell别名和像RTK(Rust Token Killer)这样的git代理工具,确保行为和输出解析的一致性。