git-clean-gone-branches

Deletes local git branches whose remote tracking branch is gone, including associated worktrees.

Updated May 11, 2026
One-click install
npx skills add https://github.com/mmnavarr/harness --skill git-clean-gone-branches-mmnavarr
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: git-clean-gone-branches
Source: https://github.com/mmnavarr/harness/tree/main/skills/git-clean-gone-branches
Command: npx skills add https://github.com/mmnavarr/harness --skill git-clean-gone-branches-mmnavarr

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes scripts (resource) components.

What problem does it solve? Over time, local repositories accumulate stale branches whose remote counterparts have been deleted after merges or abandoned work. Manually identifying and removing these branches, along with their linked worktrees, is tedious and error-prone. ## Core Features & Use Cases - Automatic Discovery: Runs git fetch --prune and parses git branch -vv output to find branches marked : gone], skipping the currently checked-out branch. - Safe Confirmation Flow: Presents the full list of stale branches and waits for explicit user confirmation before deleting anything. - Worktree Cleanup: Detects and removes associated git worktrees before deleting each branch, preventing orphaned worktree directories. - Use Case: After a sprint where several feature branches were merged and deleted on the remote, run this Skill to prune all stale local branches and their worktrees in one confirmed pass. ## Quick Start Ask the assistant to clean up local branches that no longer exist on the remote, then confirm the presented list to delete them.

Frequently Asked Questions about git-clean-gone-branches

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

FAQPage Schema
How do I delete local git branches that no longer exist on the remote?▼

Run git fetch --prune to sync remote state, then find branches marked ': gone]' in git branch -vv output and delete them with git branch -D. This Skill automates that discovery and deletion after user confirmation.

How to clean up git worktrees for deleted branches?▼

Check git worktree list for entries matching the branch name, then run git worktree remove --force on the path before deleting the branch with git branch -D. Removing the worktree first prevents orphaned directories.

Does git fetch --prune delete local branches automatically?▼

No, git fetch --prune only removes stale remote-tracking references, not local branches. Local branches whose upstream is gone must be identified via git branch -vv and deleted explicitly with git branch -D.

Why can't git delete the currently checked-out branch?▼

Git refuses to delete the active branch because it would leave the working tree in an invalid state. The discovery script skips lines marked with '*' in git branch -vv output so cleanup continues for other stale branches.

Is it safe to run git branch -D on gone branches?▼

git branch -D force-deletes without checking merge status, so unmerged local-only commits could be lost. This Skill mitigates risk by showing the full branch list and requiring explicit user confirmation before deleting anything.