Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Deletes local git branches whose remote counterparts are gone, along with their associated worktrees.
Use this skill ↓74% 87%+13 ptsof test cases passed
Passed 20 of 23 test cases with the skill, and 17 of 23 without it.
3 of 3 safety checks passed
Not used yet
Remove local branches that have been deleted on the remote (marked [gone]), including any associated git worktrees.
Fetch and prune remote refs:
git fetch --prune
List branches to identify [gone] status:
git branch -v
Branches with a + prefix have associated worktrees that must be removed before deletion.
List worktrees for reference:
git worktree list
Remove worktrees and delete [gone] branches:
git branch -v | grep '\[gone\]' | sed 's/^[+* ]//' | awk '{print $1}' | while read branch; do
echo "Processing branch: $branch"
worktree=$(git worktree list | grep "\\[$branch\\]" | awk '{print $1}')
if [ ! -z "$worktree" ] && [ "$worktree" != "$(git rev-parse --show-toplevel)" ]; then
echo " Removing worktree: $worktree"
git worktree remove --force "$worktree"
fi
echo " Deleting branch: $branch"
git branch -D "$branch"
done
Report which branches and worktrees were removed. If none were [gone], say no cleanup was needed.
Published skills whose descriptions closely match this one, with their benchmark result.
Next to this one in the catalogue, plus more from the same author.