with one click
git-clean-branches
安全查找并清理已合并或过期的 Git 分支,支持 dry-run 模式与自定义基准/保护分支
Install with Codex or Claude Copy this prompt, paste it into Codex, Claude, or another assistant, and let it review the skill page and install it for you.
Menu
安全查找并清理已合并或过期的 Git 分支,支持 dry-run 模式与自定义基准/保护分支
Install with Codex or Claude Copy this prompt, paste it into Codex, Claude, or another assistant, and let it review the skill page and install it for you.
Professional AI programming assistant with structured workflow (Research -> Ideate -> Plan -> Execute -> Optimize -> Review) for developers
专业AI编程助手,提供结构化六阶段开发工作流(研究→构思→计划→执行→优化→评审),适用于专业开发者
Quickly add a new corporate sponsor to ZCF — sponsor list by default, with optional API preset and documentation ad placements
Create pull request based on current branch changes
Automate version release and code commit using changeset
Automatically check code changes since last tag and update documentation in docs/ directory (en, zh-CN, ja-JP) and CLAUDE.md to ensure consistency with actual code implementation
Based on SOC occupation classification
| name | git-clean-branches |
| description | 安全查找并清理已合并或过期的 Git 分支,支持 dry-run 模式与自定义基准/保护分支 |
| disable-model-invocation | true |
| allowed-tools | Read(**), Exec(git fetch, git config, git branch, git remote, git push, git for-each-ref, git log), Write() |
该命令安全地识别并清理已合并或长期未更新 (stale) 的 Git 分支。
默认以只读预览 (--dry-run) 模式运行,需明确指令才会执行删除操作。
# [最安全] 预览将要清理的分支,不执行任何删除
/git-cleanBranches --dry-run
# 清理已合并到 main 且超过 90 天未动的本地分支 (需逐一确认)
/git-cleanBranches --stale 90
# 清理已合并到 release/v2.1 的本地与远程分支 (自动确认)
/git-cleanBranches --base release/v2.1 --remote --yes
# [危险] 强制删除一个未合并的本地分支
/git-cleanBranches --force outdated-feature
--base <branch>:指定清理的基准分支(默认为仓库的 main/master)。--stale <days>:清理超过指定天数未提交的分支(默认不启用)。--remote:同时清理远程已合并/过期的分支。--dry-run:默认行为。仅列出将要删除的分支,不执行任何操作。--yes:跳过逐一确认的步骤,直接删除所有已识别的分支(适合 CI/CD)。--force:使用 -D 强制删除本地分支(即使未合并)。配置与安全预检
git fetch --all --prune,确保分支状态最新。--base 参数或自动识别的 main/master 作为比较基准。分析识别(Find)
--base 的本地(及远程,如加 --remote)分支。--stale <days>,找出最后一次提交在 N 天前的分支。报告预览(Report)
--yes 参数,命令到此结束,等待用户确认后再次执行(不带 --dry-run)。执行清理(Execute)
--dry-run 且用户确认后(或带 --yes)执行。git branch -d <branch>;远程用 git push origin --delete <branch>。--force,本地删除会改用 git branch -D <branch>。为防止误删重要分支(如 develop, release/*),请在仓库的 Git 配置中添加保护规则。命令会自动读取。
# 保护 develop 分支
git config --add branch.cleanup.protected develop
# 保护所有 release/ 开头的分支 (通配符)
git config --add branch.cleanup.protected 'release/*'
# 查看所有已配置的保护分支
git config --get-all branch.cleanup.protected
--dry-run:养成先预览再执行的习惯。--base:维护长期 release 分支时,用它来清理已合并到该 release 的 feature 或 hotfix 分支。--force:除非你百分百确定某个未合并分支是无用功,否则不要强制删除。release / develop 工作流。date -d 等命令。/commit 命令共享相似的参数设计与文档结构。