branch-cleaner
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseBranch cleaner
分支清理工具
Goal
目标
Safely identify stale branches and provide explicit delete/prune commands.
安全识别过时分支,并提供明确的删除/修剪命令。
Inputs to confirm (ask if missing)
需要确认的输入信息(缺失时询问用户)
- Default branch (main/master/develop).
- Remote name (origin) and whether remote deletion is desired.
- Safety rules: keep patterns (release/, hotfix/), minimum age, merged-only.
- 默认分支(main/master/develop)。
- 远程仓库名称(通常为origin)以及是否需要删除远程分支。
- 安全规则:需保留的分支模式(如release/、hotfix/)、分支最小存在时长、仅清理已合并分支。
Workflow
工作流程
- Sync and inspect
- Run .
git fetch --prune - Check and note uncommitted changes.
git status
- Run
- Build candidate lists
- Local merged into default:
git branch --merged <base> - Local not merged (list only):
git branch --no-merged <base> - Remote merged:
git branch -r --merged <base> - Stale by date:
git for-each-ref --sort=committerdate refs/heads --format="%(committerdate:short) %(refname:short)"
- Local merged into default:
- Exclude protected branches
- Always keep , current branch, and user-provided patterns.
<base>
- Always keep
- Confirm with user
- Present candidates grouped by local vs remote.
- Provide delete commands
- Delete branches approved for deletion by the user
- 同步并检查
- 执行 命令。
git fetch --prune - 运行 并记录未提交的更改。
git status
- 执行
- 生成候选分支列表
- 已合并到默认分支的本地分支:
git branch --merged <base> - 未合并到默认分支的本地分支(仅列出):
git branch --no-merged <base> - 已合并的远程分支:
git branch -r --merged <base> - 按日期筛选的过时分支:
git for-each-ref --sort=committerdate refs/heads --format="%(committerdate:short) %(refname:short)"
- 已合并到默认分支的本地分支:
- 排除受保护分支
- 始终保留默认分支、当前分支以及用户指定需保留的分支模式。
<base>
- 始终保留默认分支
- 与用户确认
- 将候选分支按本地和远程分组展示。
- 提供删除命令
- 为用户确认删除的分支提供对应的删除命令
Optional GitHub CLI checks
可选GitHub CLI检查
- to correlate merged branches.
gh pr list --state merged --base <base> - to verify status if needed.
gh pr view <branch>
- 使用 关联已合并的分支。
gh pr list --state merged --base <base> - 必要时使用 验证分支状态。
gh pr view <branch>
Deliverables
交付内容
- Candidate lists and rationale.
- Warnings for unmerged or recently updated branches.
- Don't remove remote branches unless explicitly approved.
- 候选分支列表及筛选依据。
- 针对未合并或最近更新分支的警告信息。
- 除非用户明确批准,否则不得删除远程分支。