git-branches-prune

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Git branches prune

Git 分支清理

Process one batch per turn. Dispatch a fast subagent to build the list. Require user approval before you delete any branch. Report holds the active branch list at the top and skipped branches below.
The only git the parent runs is delete-and-prune after the gate.
每次处理一个批次调度一个轻量子Agent来构建分支列表。删除任何分支前需获得用户批准。报告顶部显示活跃分支列表,下方显示跳过的分支。
父Agent仅在审核通过后执行删除和清理的Git命令。

1. Roster

1. 分支清单

Report path:
tmp/git-branches-prune-report.md
, or
{temp-docs-dir}/git-branches-prune-report.md
when AGENTS.md names a temp-docs directory.
Read the report if it exists. Load its roster and keep names.
Read
AGENTS.md
,
CLAUDE.md
,
.cursor/rules/
,
.cursor/skills/
, and a parent-repo
AGENTS.md
if present. Build file-derived patterns:
  • Protected — long-lived / env / release trains named there
  • Temporary — feature, hotfix, merge, buffer, revert, or ticket branches
Cite a source for each pattern. Merge oracles default to
origin/main
and
origin/staging
; use the pair AGENTS.md names if it differs.
Host (GitHub / remote extras: open PRs): use the git/GitHub tool those files name. If none, probe
gh
, then GitHub MCP. If neither works: host is local git. Tell the user once: only local git access; open-PR checks skipped. GitHub access is
gh
, MCP, or local git.
Merge with the report: refresh file-derived rows from this scan; user rows stay. User wins on conflict. Ambiguous names are protected.
Write the working roster at the top of the report (keeps table unchanged). Show it. Done when the header is that roster (including host), every long-lived branch named in those files is on the protected list, temporary patterns cover feature/hotfix/merge/buffer/ticket, and keep names are in hand.
When the user states a pattern rule, add it to the roster as source
user
and write the header before the next dispatch.
markdown
undefined
报告路径:
tmp/git-branches-prune-report.md
,若AGENTS.md中指定了临时文档目录,则为
{temp-docs-dir}/git-branches-prune-report.md
若报告已存在则读取它,加载分支清单和需保留的分支名称。
读取
AGENTS.md
CLAUDE.md
.cursor/rules/
.cursor/skills/
,若存在父仓库的
AGENTS.md
也一并读取。构建从文件中提取的分支模式:
  • 受保护分支 — 其中指定的长期分支、环境分支、发布流水线分支
  • 临时分支 — 功能分支、热修复分支、合并分支、缓冲分支、回退分支或工单关联分支
为每个模式标注来源。合并基准分支默认为
origin/main
origin/staging
;若AGENTS.md中指定了其他分支对,则使用指定的分支。
托管平台(GitHub / 远程额外检查:开放PR):使用上述文件中指定的Git/GitHub工具。若未指定,则先尝试
gh
,再尝试GitHub MCP。若两者都不可用,则托管平台为本地Git。需告知用户一次:仅支持本地Git访问,将跳过开放PR检查。GitHub访问方式包括
gh
、MCP或本地Git。
与现有报告合并:刷新本次扫描得到的文件衍生条目;用户自定义条目保留。若发生冲突,以用户设置为准。名称模糊的分支将被标记为受保护分支。
将当前分支清单写入报告顶部(需保留的分支表格保持不变)并展示。当报告头部包含该分支清单(含托管平台)、所有文件中指定的长期分支均在受保护列表中、临时分支模式覆盖功能/热修复/合并/缓冲/工单分支,且已获取需保留的分支名称时,本步骤完成。
当用户指定模式规则时,将其添加到分支清单中,来源标记为
user
,并在下次调度前更新报告头部。
markdown
undefined

Git branches prune

Git branches prune

Roster

Roster

Oracles:
origin/main
,
origin/staging
Host: gh | github MCP | local git
Oracles:
origin/main
,
origin/staging
Host: gh | github MCP | local git

Protected

Protected

PatternSource
envs/*
AGENTS.md
release/*
user 2026-08-13
PatternSource
envs/*
AGENTS.md
release/*
user 2026-08-13

Temporary

Temporary

PatternSource
JIRA-
AGENTS.md
feature/
hotfix/
merge
buffer
revert-
user 2026-08-13
PatternSource
JIRA-
AGENTS.md
feature/
hotfix/
merge
buffer
revert-
user 2026-08-13

Keeps

Keeps

BranchAuthorLatest Commit DateReasonAnalysis Date
undefined
BranchAuthorLatest Commit DateReasonAnalysis Date
undefined

2. Dispatch

2. 调度

Launch one cheap subagent that can run git (this env's shell / bash / general runner). Pick a cheap fast family this env actually offers — no version pins, inherit only if none exist:
Haiku, Composer, Gemini Flash, GPT mini, DeepSeek, Qwen Coder, Llama 8B, Codestral, Yi-Coder
Point it at chunk.md. Give it:
  • the roster (protected + temporary + oracles + host)
  • exclude: every branch already in Keeps
  • year: oldest unfinished, or the year in progress
Done when the return has a year, a candidate table of ≤20 rows, and a skipped list. Every candidate row has main, staging, and propose. Keep names do not appear.
If the return is incomplete, dispatch again naming the gap. Parent does not inventory, classify, or merge-check.
启动一个可运行Git的轻量子Agent(使用当前环境的shell/bash/通用运行器)。选择当前环境实际提供的轻量快速模型系列——不指定版本,仅在无可用模型时继承默认设置:
Haiku, Composer, Gemini Flash, GPT mini, DeepSeek, Qwen Coder, Llama 8B, Codestral, Yi-Coder
将其指向chunk.md,并提供以下信息:
  • 分支清单(受保护分支+临时分支+合并基准分支+托管平台)
  • 排除:所有已在“需保留分支”列表中的分支
  • 年份:最早未处理的年份,或当前年份
当返回结果包含年份、≤20行的候选分支表格和跳过分支列表,且每个候选分支行包含与main、staging的对比信息及处理建议,且需保留的分支名称未出现在候选列表中时,本步骤完成。
若返回结果不完整,需重新调度并指出缺失的信息。父Agent不执行分支盘点、分类或合并检查操作。

3. Gate

3. 审核

Show proposed delete, keep, and skipped. Stop. Done when the user names the branches to delete, or approves the proposed-delete set. Pattern rules stated here go to the roster (step 1).
展示建议删除、保留和跳过的分支列表,然后暂停。当用户指定需删除的分支,或批准建议删除的分支集合时,本步骤完成。在此处指定的模式规则将添加到分支清单中(步骤1)。

4. Record

4. 记录

Append a row for every skipped branch from this batch: user keep, not merged, open PR, current checkout, or other can't-delete. Reason on the row. Keeps is keep-only.
Done when every keep/can't-delete from this batch has a row and no pruned name was added.
为本次批次中每个跳过的分支添加一行记录:用户要求保留、未合并、存在开放PR、当前检出分支或其他无法删除的原因。每行需注明原因。“需保留分支”列表仅包含需保留的分支。
当本次批次中所有需保留/无法删除的分支均已添加记录,且已清理的分支名称未被添加到列表中时,本步骤完成。

5. Delete

5. 删除

Only user-approved names. Strip
origin/
once (
origin/origin/feature/X
origin/feature/X
). Current checkout stays. Local
git
unless the roster host names a different delete tool.
bash
git push origin --delete <name> [<name> ...]
git branch -d <name>   # only if a local branch exists; never -D
git fetch origin --prune
Done when
git show-ref
has none of the deleted names.
仅删除用户批准的分支名称。移除一次
origin/
前缀(如
origin/origin/feature/X
origin/feature/X
)。当前检出的分支保留。除非分支清单中指定了其他删除工具,否则使用本地
git
命令。
bash
git push origin --delete <name> [<name> ...]
git branch -d <name>   # only if a local branch exists; never -D
git fetch origin --prune
git show-ref
命令输出中不再包含已删除的分支名称时,本步骤完成。

6. Next batch

6. 下一批次

Re-read the report. Same year if temporary candidates remain; otherwise the next year. Dispatch again. Stop when years are exhausted or the user ends the pass.
重新读取报告。若仍有临时分支候选,则继续处理同一年份;否则处理下一年份。再次调度。当年份处理完毕或用户终止流程时停止。

Rationalizations

说明

ExcuseReality
"I know the env branches"Roster from files + report header this run.
"User said the pattern, I'll remember"User rows go in the roster header.
"I'll open GitHub in a browser"Host is gh, MCP, or local git. Tell the user.
"Pin composer-2.5-fast"Cheap family this env offers. No version pins.
"Faster to run the git myself"Dispatch. Parent presents, gates, records, deletes.
"Skip the report"Write roster and keeps before the next dispatch.
"Merged everywhere, just delete"Gate first. The list is a proposal.
"
-D
because
-d
refused"
Stop. Tell the user. User must say force.
借口实际规则
"I know the env branches"分支清单来源于文件+本次运行的报告头部。
"User said the pattern, I'll remember"用户自定义规则需添加到分支清单头部。
"I'll open GitHub in a browser"托管平台为gh、MCP或本地Git。需告知用户。
"Pin composer-2.5-fast"使用当前环境提供的轻量模型系列,不指定版本。
"Faster to run the git myself"需调度子Agent。父Agent仅负责展示、审核、记录和删除操作。
"Skip the report"下次调度前必须写入分支清单和需保留的分支列表。
"Merged everywhere, just delete"必须先经过审核。列表仅为建议。
"
-D
because
-d
refused"
停止操作并告知用户。必须获得用户的强制删除指令。