跳到正文
cccskills
免费在 GitHub 公开

git-clean-branches

Find merged or inactive Git branches, preview cleanup candidates, and delete selected branches after confirmation. Choose a comparison branch, protect important branches with configurable rules, and optionally include remote branches.

中文简介正在准备中。当前显示英语简介。

原文查看原文说明

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

查看安装方法

适用场景

  • Previewing branch cleanup candidates
  • Removing branches already merged into a release branch
  • Finding branches with no recent commits
  • Cleaning up local and remote branches

包含的文件(1)

  • SKILL.md4.3 KB

SKILL.md(原文)

安装前可以查看交给 AI 代理的指令内容。

Claude Command: Clean Branches

该命令安全地识别并清理已合并或长期未更新 (stale) 的 Git 分支。 默认以只读预览 (--dry-run) 模式运行,需明确指令才会执行删除操作。


Usage

# [最安全] 预览将要清理的分支,不执行任何删除
/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, 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

Best Practices for Embedded Devs

  • 优先 --dry-run:养成先预览再执行的习惯。
  • 活用 --base:维护长期 release 分支时,用它来清理已合并到该 release 的 feature 或 hotfix 分支。
  • 谨慎 --force:除非你百分百确定某个未合并分支是无用功,否则不要强制删除。
  • 团队协作:在清理共享的远程分支前,先在团队频道通知一声。
  • 定期运行:每月或每季度运行一次,保持仓库清爽。

Why This Version Is Better

  • ✅ 更安全:默认只读预览,且有可配置的保护分支列表。
  • ✅ 更灵活:支持自定义基准分支,完美适配 release / develop 工作流。
  • ✅ 更兼容:避免了在不同系统上行为不一的 date -d 等命令。
  • ✅ 更直观:将复杂的 16 步清单,浓缩成一个带安全选项的、可直接执行的命令。
  • ✅ 风格一致:与 /commit 命令共享相似的参数设计与文档结构。

评价

还没有评价。欢迎分享你的使用感受。

评论

无需登录即可发表。欢迎分享使用感受、提问,或说明在哪些环境下无法运行。

还没有评论。来写第一条吧。

提交后会立即公开。请勿填写邮箱、电话等个人信息。URL 最多 2 个。

0 / 1000 字

此表单受 reCAPTCHA 保护,适用 Google 的隐私权政策和服务条款。

同一仓库的技能

bmad-init

免费

Install or update BMad-Method (V6) in a project after checking existing installations. The skill also fixes a known output-folder issue, updates Git ignore rules, and provides next steps for using the installed workflows.

中文简介正在准备中。当前显示英语简介。

  • Set up BMad-Method (V6) for Claude Code
  • Run a quick update on an existing V6 installation
  • Check for an older V4 installation before setup
UfoMiao/zcf60812026年8月31日 更新

bmad-init

免费

Set up or update BMad-Method V6 in a project, detect older installations, fix a known output folder issue, and adjust Git ignore rules, with guidance on what to do next.

中文简介正在准备中。当前显示英语简介。

  • Installing BMad-Method V6 in a project
  • Updating an existing V6 installation
  • Checking for an older V4 installation
UfoMiao/zcf60812026年8月31日 更新

feat

免费

Turn feature requests into documented plans, revise them through discussion, and carry out implementation with progress tracking. Frontend work includes checking for a UI design and arranging design work when needed.

中文简介正在准备中。当前显示英语简介。

  • Turning a feature idea into a development plan
  • Revising a plan after feedback
  • Implementing tasks from an agreed plan
UfoMiao/zcf60812026年8月31日 更新

feat

免费

Guide new feature work from requirements and planning through revisions and implementation. Create Markdown plans with acceptance criteria, track progress, and ensure frontend tasks have a UI design before development begins.

中文简介正在准备中。当前显示英语简介。

  • Turn a feature idea into an implementation plan
  • Revise a plan based on feedback
  • Start implementation from an agreed plan
UfoMiao/zcf60812026年8月31日 更新

Find Git branches that have been merged or inactive for a chosen period. Preview cleanup candidates, exclude protected branches, and delete local or remote branches using a selected base branch and confirmation options.

中文简介正在准备中。当前显示英语简介。

  • Find merged branches to clean up
  • Review branches with no recent commits
  • Clean up branches merged into a release
UfoMiao/zcf60812026年8月31日 更新

Use Git changes to generate Conventional Commits messages, a format that labels each change by type, and create commits. The skill suggests splitting unrelated changes and supports explicit scope, type, sign-off, and amendments to the previous commit.

中文简介正在准备中。当前显示英语简介。

  • Generate a commit message from staged changes
  • Split unrelated changes into separate commits
  • Specify a commit type and scope
UfoMiao/zcf60812026年8月31日 更新

查看 UfoMiao 的全部技能

报告此技能的问题