branch-cleanup
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinesebranch-cleanup
branch-cleanup
Report stale remote branches and propose safe deletion. Never delete a branch without
explicit authorization for that batch.
报告陈旧的远程分支并提出安全删除建议。未经当前批次的明确授权,绝不删除任何分支。
What this skill is NOT for
本 skill 不适用于
- Local git worktree management (,
git worktree add,list) — out of scope.prune - One-time repository merge-default and branch-protection setup — use . This skill only reads
/gh-bootstrapand existing rulesets; it proposes turning the setting on but the write happens throughdelete_branch_on_merge, the same endpointgh api -X PATCHuses in its step 2./gh-bootstrap
- 本地 Git worktree 管理(、
git worktree add、list)——不在范围内。prune - 一次性设置 repository 合并默认值和 branch-protection rulesets——请使用 。 本 skill 只读取
/gh-bootstrap和现有 rulesets;它会提议开启此设置, 但实际写入通过delete_branch_on_merge完成,与gh api -X PATCH在步骤 2 中使用的 endpoint 相同。本 skill 不重复该步骤。/gh-bootstrap
Protocol
协议
1. Check delete-branch-on-merge
1. 检查 delete-branch-on-merge
bash
REPO="$(gh repo view --json nameWithOwner --jq '.nameWithOwner')"
gh api "repos/$REPO" --jq '.delete_branch_on_merge'If , propose enabling it and explain the effect: GitHub deletes a branch's remote
ref automatically once its pull request merges. Ask for explicit authorization before
running the write —
see step 2 for the full merge-defaults , which this skill does not
duplicate.
falsegh api -X PATCH repos/{owner}/{repo} -F delete_branch_on_merge=true/gh-bootstrapPATCHbash
REPO="$(gh repo view --json nameWithOwner --jq '.nameWithOwner')"
gh api "repos/$REPO" --jq '.delete_branch_on_merge'如果结果为 ,则提议启用此设置并说明其效果:pull request 合并后,GitHub 会自动删除该分支的 remote ref。在运行 写入操作前,必须获得明确授权——完整的 merge-defaults 请参阅 步骤 2,本 skill 不予重复。
falsegh api -X PATCH repos/{owner}/{repo} -F delete_branch_on_merge=truePATCH/gh-bootstrap2. Report stale branches
2. 报告陈旧分支
Run the bundled script from the repository root:
bash
python3 "$BRANCH_CLEANUP_HELPER" --days 90 --github "$REPO"Resolve from the loaded directory
(), resolving symlinks first. For each remote branch the script
reports:
BRANCH_CLEANUP_HELPERSKILL.mdscripts/stale_branches.py- Last commit date and author ().
git log -1 - Ahead/behind counts against the default branch ().
git rev-list --left-right --count - Merged status ().
git branch -r --merged <default> - Whether an open pull request targets the branch (), when
gh pr list --head <branch> --state open --json numberis passed.--github - Whether a ruleset protects the branch (), when
gh api repos/{owner}/{repo}/rules/branches/ {branch}is passed.--github
The output is a table sorted by age (oldest first) with a column of
, , or . See for the exact classification
rule.
recommendationkeeparchivedeletereferences/policy.md从 repository 根目录运行随附的脚本:
bash
python3 "$BRANCH_CLEANUP_HELPER" --days 90 --github "$REPO"从已加载的 所在目录解析 (),并首先解析 symlink。对于脚本报告的每个远程分支:
SKILL.mdBRANCH_CLEANUP_HELPERscripts/stale_branches.py- 最后一次提交的日期和作者()。
git log -1 - 相对默认分支的 ahead/behind 数量()。
git rev-list --left-right --count - 合并状态()。
git branch -r --merged <default> - 是否有未关闭的 pull request 以该分支为目标(),前提是传入了
gh pr list --head <branch> --state open --json number。--github - 该分支是否受到 ruleset 保护(),前提是传入了
gh api repos/{owner}/{repo}/rules/branches/{branch}。--github
输出结果是一张按分支年龄排序( oldest first)的表格,其中 列的值为 、 或 。准确的分类规则请参阅 。
recommendationkeeparchivedeletereferences/policy.md3. Local hygiene
3. 本地清理
Report-only, no deletion:
bash
git fetch --prune
git branch --merged <default>List the locally merged branches for the user. Do not delete local branches without the
same per-batch authorization required in step 4.
仅报告,不删除:
bash
git fetch --prune
git branch --merged <default>向用户列出本地已合并的分支。除非获得步骤 4 所要求的同等级逐批次授权,否则不得删除本地分支。
4. Deletion is never automatic
4. 绝不自动删除
For every branch classified , print the exact command:
deletebash
git push origin --delete <branch>Always exclude the default branch, any protected branch, and any branch with an open pull
request from deletion — the script enforces this by classifying those branches
regardless of age. Require explicit user authorization before running any printed command,
and confirm the authorized batch matches the printed list exactly.
keep对于每个被分类为 的分支,输出精确命令:
deletebash
git push origin --delete <branch>始终将默认分支、任何受保护分支以及任何存在未关闭 pull request 的分支排除在删除范围之外——无论分支年龄如何,脚本都会将这些分支分类为 。运行任何已输出的命令前,都必须获得用户的明确授权,并确认授权批次与输出列表完全一致。
keep5. Optional scheduled report workflow
5. 可选的定时报告工作流
Copy to if the
user wants a recurring report. It only writes a job summary — it never deletes a branch.
is pinned by SHA.
assets/stale-branch-report.yml.github/workflows/stale-branch-report.ymlactions/checkout如果用户需要定期报告,请将 复制到 。该工作流只写入 job summary,绝不会删除分支。 已通过 SHA 固定版本。
assets/stale-branch-report.yml.github/workflows/stale-branch-report.ymlactions/checkout6. Verify
6. 验证
Re-run the script and confirm the printed table matches the branches actually present on
the remote (). Confirm no recommendation includes the default
branch, a protected branch, or a branch with an open pull request.
git branch -rdelete重新运行脚本,并确认输出的表格与远程实际存在的分支()一致。确认任何 建议均不包含默认分支、受保护分支或存在未关闭 pull request 的分支。
git branch -rdeleteCross-references
交叉引用
- — one-time repository merge defaults and branch-protection rulesets.
/gh-bootstrap - — local pre-commit hook checks, unrelated to branch lifecycle.
/prek - — broader repository health, including community-standards files.
/oss-hygiene
- ——一次性设置 repository 合并默认值和 branch-protection rulesets。
/gh-bootstrap - ——本地 pre-commit hook 检查,与分支生命周期无关。
/prek - ——更全面的 repository 健康检查,包括 community-standards 文件。
/oss-hygiene