git-detect-merged

Detect 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-detect-merged
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: git-detect-merged
Source: https://github.com/lestrrat/claude-code/tree/main/skills/git-detect-merged
Command: npx skills add https://github.com/lestrrat/claude-code --skill git-detect-merged

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Branch clutter and uncertain history make cleanup hard. This Skill identifies local branches and worktrees that have already been merged into a target branch, guiding safe cleanup and history preservation.

Core Features & Use Cases

  • Regular merge detection: detects branches that have been merged into the target using the standard merge-base and --merged checks, while applying a pre-filter to avoid deleting unrelated history.
  • Squash merge detection: detects squash-merged branches by combining single-commit cherry checks with patch-id comparisons to confirm full integration.
  • Active work detection: flags worktrees that are dirty, have untracked changes, or are currently checked out to prevent accidental deletion.

Quick Start

Run git-detect-merged to identify merged branches and worktrees against the target branch.

Frequently Asked Questions about git-detect-merged

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

FAQPage Schema
How do I identify which local Git branches have been merged into main?

To identify merged branches, the Skill checks local branches against a target branch using standard merge-base and --merged checks. It applies a pre-filter to avoid deleting unrelated history before flagging branches for safe cleanup.

How does Git detect squash-merged branches for cleanup?

Detecting squash-merged branches involves combining single-commit cherry checks with patch-id comparisons. This confirms whether the changes are fully integrated into the target branch, enabling safe deletion of squash-merged work.

Can I automatically delete Git worktrees that are dirty or have untracked changes?

You should not automatically delete dirty worktrees. The Skill actively flags worktrees with untracked changes, dirty states, or active checkouts to prevent accidental deletion and preserve uncommitted work during cleanup.

What Git commands are needed to check if a branch is merged?

Checking branch merge status requires a local Git environment and uses standard commands such as git branch, git merge-base, git cherry, and git patch-id to accurately classify both regular and squash merge statuses.

What is the best way to clean up stale branches and worktrees in a Git repository?

The best way to clean up stale branches and worktrees is to run the Skill against a target branch like main. It identifies both regular and squash-merged entries while protecting active work, guiding safe history preservation and pruning.