git-cleanup-merged

Identify and remove local branches and worktrees merged into a target branch.

2|Updated Feb 24, 2026
One-click install
npx skills add https://github.com/lestrrat/claude-code --skill git-cleanup-merged
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: git-cleanup-merged
Source: https://github.com/lestrrat/claude-code/tree/main/skills/git-cleanup-merged
Command: npx skills add https://github.com/lestrrat/claude-code --skill git-cleanup-merged

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Clean up local branches and worktrees that have been merged into a target branch, reducing clutter and avoiding confusion about stale refs.

Core Features & Use Cases

  • Detects merged branches and active worktrees against a target branch (default: main).
  • Enforces safety rules: never delete the target or main branch; requires user confirmation before deletion; reports a clear summary of what will be removed and what will be skipped.
  • Supports a safe, repeatable cleanup workflow in local repositories, improving maintainability and reducing repo drift.

Quick Start

Run the git-cleanup-merged workflow to review and remove merged branches and worktrees after confirmation.

Frequently Asked Questions about git-cleanup-merged

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

FAQPage Schema
How do I safely clean up local git branches that have been merged?

To clean up merged branches safely, this Skill detects branches merged into a target branch and requires explicit user confirmation before deletion. It enforces safety rules by never deleting the target or main branch, reporting a clear summary of removed and skipped branches.

Can I remove git worktrees that are no longer needed after merging?

Yes, you can remove active worktrees after merging. The workflow identifies worktrees associated with branches merged into a target branch, summarizes the candidates for cleanup, and asks for your confirmation before removing them.

What is the safest way to prune stale git branches in a local repository?

The safest way to prune stale branches is to use a workflow that detects merges against a target branch and requires user confirmation. This Skill defaults to using the safe -d flag for deletion and only applies the forceful -D flag with explicit user consent.

Does git branch cleanup work against a target branch other than main?

Yes, git branch cleanup works against a target branch other than main. The default target is main, but you can specify a different target branch, and the workflow will detect all local branches and worktrees merged into that specified target.

Why should I use a confirmation prompt before deleting merged branches?

A confirmation prompt prevents the accidental loss of unmerged work. Before deleting merged branches and worktrees, this Skill provides a clear summary of what will be removed and skipped, ensuring you review the candidates and explicitly approve the action before any deletion occurs.