git-clean-branches

Featured

安全查找并清理已合并或过期的 Git 分支,支持 dry-run 模式与自定义基准/保护分支

AI & Automation 6,083 stars 421 forks Updated 1 weeks ago MIT

Install

View on GitHub

Quality Score: 91/100

Stars 20%
100
Recency 20%
90
Frontmatter 20%
70
Documentation 15%
100
Issue Health 10%
50
License 10%
100
Description 5%
100

Skill Content

# Claude Command: Clean Branches 该命令**安全地**识别并清理**已合并**或**长期未更新 (stale)** 的 Git 分支。 默认以**只读预览 (`--dry-run`)** 模式运行,需明确指令才会执行删除操作。 --- ## Usage ```bash # [最安全] 预览将要清理的分���,不执行任何删除 /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 ``` ### Options - `--base <branch>`:指定清理的基准分支(默认为仓库的 `main`/`master`)。 - `--stale <days>`:清理超过指定天数未提交的分支(默认不启用)。 - `--remote`:同时清理远程已合并/过期的分支。 - `--dry-run`:**默认行为**。仅列出将要删除的分支,不执行任何操作。 - `--yes`:跳过逐一确认的步骤,直接删除所有已识别的分支(适合 CI/CD)。 - `--force`:使用 `-D` 强制删除本地分支(即使未合并)。 --- ## What This Command Does 1. **配置与安全预检** - **更新信息**:自动执行 `git fetch --all --prune`,确保分支状态最新。 - **读取保护分支**:从 Git 配置读取不应被清理的分支列表(见下文“Configuration”)。 - **确定基准**:使用 `--base` 参数或自动识别的 `main`/`master` 作为比较基准。 2. **分析识别(Find)** - **已合并分支**:找出已完全合并到 `--base` 的本地(及远程,如加 `--remote`)分支。 - **过期分支**:如指定 `--stale <days>`,找出最后一次提交在 N 天前的分支。 - **排除保护分支**:从待清理列表中移除所有已配置的保护分支。 3. **报告预览(Report)** - 清晰列出“将要删除的已合并分支”与“将要删除的过期分支”。 - 若无 `--yes` 参数,**命令到此结束**,等待用户确认后再次执行(不带 `--dry-run`)。 4. **执行清理(Execute)** - **仅在不带 `--dry-run` 且用户确认后**(或带 `--yes`)执行。 - 逐一删除已识别的分支,除非用户在交互式确认中选择跳过。 - 本地用 `git branch -d <branch>`;远程用 `git push origin --delete <branch>`。 - 若指定 `--force`,本地删除会改用 `git branch -D <branch>`。 --- ## Configuration (一次配置,永久生效) 为防止误删重要分支(如 `develop`...

Details

Author
UfoMiao
Repository
UfoMiao/zcf
Created
1 years ago
Last Updated
1 weeks ago
Language
TypeScript
License
MIT

Integrates with

Similar Skills

Semantically similar based on skill content — not just same category