se-clean-gone-branches

Delete local Git branches with deleted remote tracking branches and their worktrees.

Updated May 7, 2026
One-click install
npx skills add https://github.com/simonwjackson/pi-software-engineering --skill se-clean-gone-branches
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: se-clean-gone-branches
Source: https://github.com/simonwjackson/pi-software-engineering/tree/main/skills/se-clean-gone-branches
Command: npx skills add https://github.com/simonwjackson/pi-software-engineering --skill se-clean-gone-branches

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes scripts (resource) components.

What problem does it solve?

This skill helps teams maintain a clean local Git repository by removing local branches whose remote tracking branches have been deleted. It also handles removing associated worktrees to fully prune stale work contexts.

Core Features & Use Cases

  • Discover gone branches by fetching remote state and scanning git branch -vv for : gone] markers.
  • Confirm and delete identified branches, with automatic worktree cleanup when present.
  • Generate a concise report of removed worktrees and branches to keep a clear audit trail.
  • Use Case: After a remote branch is deleted upstream, run this skill to prune corresponding local branches and any linked worktrees to avoid confusion.

Quick Start

Ask your AI to run the script to prune local branches that no longer exist on the remote.

Frequently Asked Questions about se-clean-gone-branches

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

FAQPage Schema
How do I clean up local Git branches that have been deleted on the remote?

To clean up local Git branches, fetch remote state with git fetch --prune and scan git branch -vv for branches marked gone. This script confirms and deletes identified branches while automatically removing linked worktrees.

How does Git branch pruning work for repositories with multiple worktrees?

Git branch pruning discovers gone branches via git fetch --prune, then removes any associated worktrees before deleting the branches. This prevents stale work contexts from blocking branch deletion and maintains a clean local repository.

What is the best way to delete stale local branches after an upstream remote branch is removed?

The best way to delete stale local branches is scanning git branch -vv output for : gone] markers after fetching. This script prompts for confirmation, removes linked worktrees, and deletes branches with an audit trail report.

Does Git branch cleanup work safely with branches that have active worktrees?

Git branch cleanup handles worktrees safely by detecting associated worktrees when present and removing them automatically before deleting the branch. This ensures full pruning of stale work contexts without manual intervention.

Can I automate pruning local Git branches without manually checking each upstream?

You can automate pruning local Git branches by running a script that fetches remote state and scans branch tracking markers. It discovers gone branches automatically, prompts for confirmation, and removes both branches and worktrees.

Why does Git keep local branches after the remote tracking branch is deleted?

Git keeps local branches after remote deletion because git fetch --prune only removes remote-tracking references, not local branches. This script identifies those orphaned local branches using git branch -vv markers and deletes them.