git-branch-prune
v0.0.1
Published
A cross-platform automated Git branch cleaning and management tool with advanced filtering, scheduling, and safety features. Automatically identifies and removes stale branches based on custom rules, with preview mode, interactive confirmation, and rollba
Maintainers
Readme
git-branch-prune
一个跨平台的自动化 Git 分支清理工具,支持智能过滤、安全删除和计划任务。
安装
npm install -g git-branch-prune命令别名:gbp
快速开始
# 预览过期分支(超过 7 天的已合并分支)
gbp --preview --min-age 7
# 交互式清理
gbp --min-age 14 --prefix feature/ bugfix/
# CI 模式(非交互)
gbp --yes --min-age 30核心选项
-P, --preview- 预览模式,不删除-y, --yes- 跳过确认(CI 模式)-a, --min-age <days>- 分支最小天数(默认:7)-p, --prefix <...>- 指定分支前缀-m, --main-branch <name>- 主分支名称(默认:main)-o, --only-merged- 仅清理已合并分支(默认:true)--recover- 恢复已删除分支
配置文件
创建 git-branch-prune.config.yaml:
mainBranch: main
branchPrefixes: ["feature/", "bugfix/"]
cleanupRules:
minAgeDays: 7
onlyMerged: true
safety:
interactive: true
protectedBranches: ["main", "develop"]
logging:
level: "info"使用配置运行:
gbp --config git-branch-prune.config.yaml --preview安全特性
- 预览模式:先确认再删除
- 受保护分支:默认不删除 main/develop
- 删除日志:
git-branch-prune-deletions.log(支持回滚) - 交互确认:可批量或逐个确认
示例
# 安装系统调度器(每天凌晨执行)
gbp --install-scheduler --cron "0 0 * * *" --min-age 7
# 清理所有过期分支(含未合并)
gbp --min-age 30 --not-only-merged
# 恢复删除的分支
gbp --recover
# 生成 HTML 报告
gbp --report --report-format html许可证
MIT
