clean-branches

Remove stale local git branches and associated worktrees after remote deletion.

Updated May 23, 2026
One-click install
npx skills add https://github.com/devturco/thiago-dev-template --skill clean-branches-devturco
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: clean-branches
Source: https://github.com/devturco/thiago-dev-template/tree/main/.claude/skills/clean-branches
Command: npx skills add https://github.com/devturco/thiago-dev-template --skill clean-branches-devturco

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

When branches are deleted on the remote, your local repository can accumulate stale branches that clutter your workflow and confuse what code is still active.

Core Features & Use Cases

  • Find deleted-remote branches: Fetches with pruning and targets branches marked as gone to identify what should be removed.
  • Clean related worktrees: Detects and force-removes any worktrees associated with those stale branches, preventing lingering directories.
  • Deletes local branches: Force-deletes the identified local branches while avoiding accidental removal of the current top-level worktree.

Quick Start

Use the clean-branches skill to remove local git branches that have been deleted from the remote and clean up any associated worktrees.

Frequently Asked Questions about clean-branches

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

FAQPage Schema
How do I delete stale local git branches after they are removed from the remote?

To delete stale local git branches, you can fetch with pruning to detect branches marked as [gone] and force-delete them locally. This removes branches that were deleted on the remote but still exist in your local repository.

How do I clean up git worktrees associated with deleted remote branches?

Cleaning up git worktrees involves detecting those linked to stale branches and force-removing them. This prevents lingering worktree directories from cluttering your development setup after remote deletions.

What is the best way to handle repository hygiene in a monorepo with multiple worktrees?

Repository hygiene in a monorepo with multiple worktrees requires fetching with pruning to identify [gone] branches. You then safely remove associated worktrees and force-delete the stale branches to prevent local drift.

Why do my local branches still show up after being merged and deleted on the remote?

Local branches still show up because remote deletions do not automatically sync to your local repository. You must fetch with pruning to detect them as [gone] and explicitly remove them to clean up the local state.

Is it safe to force delete branches when cleaning up stale worktrees?

It is safe to force delete stale branches when the process specifically targets [gone] branches and avoids removing the current top-level worktree. This ensures active branches and your current working directory are protected from accidental deletion.