git-branch-cleanup

Remove merged or deleted git branches while protecting critical ones.

2|Updated Jun 2, 2024
One-click install
npx skills add https://github.com/magnusrodseth/dotfiles --skill git-branch-cleanup-magnusrodseth
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: git-branch-cleanup
Source: https://github.com/magnusrodseth/dotfiles/tree/main/.claude/skills/git-branch-cleanup
Command: npx skills add https://github.com/magnusrodseth/dotfiles --skill git-branch-cleanup-magnusrodseth

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes scripts (resource) components.

What problem does it solve?

This Skill provides a safe way to remove stale and merged local git branches without risking the deletion of important branches, protecting the current branch, default branch, and any worktree-checked-out branch.

Core Features & Use Cases

  • Safely Delete Merged Branches: Identifies and removes local branches that are already merged, squash/rebase-merged, or whose remote was deleted.
  • Protect Critical Branches: Ensures the current branch, default branch, and any worktree-checked-out branch are never deleted.
  • Classification & Review: Lists branches that are merged but need further confirmation before deletion.
  • Pruning: Optionally performs a git fetch --prune to accurately detect remote branches that have been deleted.

Quick Start

Use the git-branch-cleanup skill to safely remove stale branches. First, run the fetch command to ensure all information is up to date:

bash scripts/cleanup-branches.sh --fetch

Review the list of branches and re-run the script with --force to remove them:

bash scripts/cleanup-branches.sh --force

Frequently Asked Questions about git-branch-cleanup

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I safely delete merged git branches without removing important ones?

To safely delete merged git branches, use a script that targets squash or rebase-merged branches while explicitly protecting the current, default, and worktree-checked-out branches from removal.

What is the best way to clean up stale local git branches after remote deletion?

The best way to clean up stale local git branches is to run a fetch --prune command first to detect deleted remote branches, then review the classified list and execute a forced cleanup to remove them locally.

Does git branch cleanup protect the default and currently checked out branches?

Yes, git branch cleanup safeguards the default branch, the current branch, and any worktree-checked-out branch. It ensures these critical branches are never deleted during the stale branch removal process.

Can I identify squash or rebase-merged branches for deletion in git?

Yes, you can identify squash or rebase-merged branches for deletion using a branch cleanup script. It classifies these branches alongside standard merged ones, listing them for your review before you force the removal.

What are the limitations of automated git branch removal?

Automated git branch removal requires a basic understanding of git operations to interpret script output. It also requires explicit confirmation to delete classified branches, protecting against accidental loss of unmerged work.