git-clean-gone-branches

Delete local Git branches with deleted remote tracking branches.

6|Updated Jan 29, 2023
One-click install
npx skills add https://github.com/rethinkhealth/glion --skill git-clean-gone-branches-rethinkhealth
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: git-clean-gone-branches
Source: https://github.com/rethinkhealth/glion/tree/main/.agents/skills/git-clean-gone-branches
Command: npx skills add https://github.com/rethinkhealth/glion --skill git-clean-gone-branches-rethinkhealth

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires git, bash, sed, awk, and includes scripts (resource) components.

What problem does it solve?

Clean up local git branches whose remote tracking branch has been deleted, including any associated worktrees.

Core Features & Use Cases

  • Discovers local branches whose remote tracking branch has been removed.
  • Safely deletes eligible branches and any linked worktrees, preserving the current branch.
  • Runs a small script located at scripts/clean-gone and uses Git tooling to ensure deterministic results.

Quick Start

Run the cleanup to remove all local branches whose remote branches no longer exist.

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 when the remote branch is already deleted?

To delete local git branches whose remote tracking branch has been deleted, you can run a script that executes git fetch --prune and parses git branch -vv output for gone markers. It then safely removes the eligible local branches.

Can I clean up gone git branches that have associated worktrees?

Yes, you can safely clean up gone git branches that have associated worktrees. The cleanup script detects branches with linked worktrees and deletes both the branch and its worktree during the maintenance process.

What is the best way to find stale local git branches after pruning remotes?

The best way to find stale local git branches after pruning remotes is to parse the output of git branch -vv for the gone marker. This identifies branches whose remote tracking branch has been removed by the fetch operation.

Does the branch cleanup script protect the currently checked-out branch?

Yes, the branch cleanup script includes safety checks to protect the currently checked-out branch. It ensures that the active branch is preserved while deleting local branches whose remote tracking branch has been deleted.

Do I need bash and sed installed to remove gone branches from my repository?

Yes, you need bash, sed, and awk installed to run the repository maintenance script. These command-line dependencies are required to parse git branch output and execute the branch deletion commands.

Why do stale local branches remain after I run git fetch --prune?

Stale local branches remain after git fetch --prune because that command only removes remote tracking references. You must separately parse git branch -vv for gone markers and explicitly delete the corresponding local branches to clean them up.