spacehub

surshar / claude-code

Claude Code is an agentic coding tool that lives in your terminal, understands your codebase, and helps you code faster by executing routine tasks, explaining complex code, and handling git workflows - all through natural language commands.

Built by Anthropic · github.com/anthropics

claude-code / plugins / commit-commands / commands / clean_gone.md
53 lines · 1.8 KBPreviewCodeRaw
1---
2description: Cleans up all git branches marked as [gone] (branches that have been deleted on the remote but still exist locally), including removing associated worktrees.
3---
4
5## Your Task
6
7You need to execute the following bash commands to clean up stale local branches that have been deleted from the remote repository.
8
9## Commands to Execute
10
111. **First, list branches to identify any with [gone] status**
12 Execute this command:
13 ```bash
14 git branch -v
15 ```
16
17 Note: Branches with a '+' prefix have associated worktrees and must have their worktrees removed before deletion.
18
192. **Next, identify worktrees that need to be removed for [gone] branches**
20 Execute this command:
21 ```bash
22 git worktree list
23 ```
24
253. **Finally, remove worktrees and delete [gone] branches (handles both regular and worktree branches)**
26 Execute this command:
27 ```bash
28 # Process all [gone] branches, removing '+' prefix if present
29 git branch -v | grep '\[gone\]' | sed 's/^[+* ]//' | awk '{print $1}' | while read branch; do
30 echo "Processing branch: $branch"
31 # Find and remove worktree if it exists
32 worktree=$(git worktree list | grep "\\[$branch\\]" | awk '{print $1}')
33 if [ ! -z "$worktree" ] && [ "$worktree" != "$(git rev-parse --show-toplevel)" ]; then
34 echo " Removing worktree: $worktree"
35 git worktree remove --force "$worktree"
36 fi
37 # Delete the branch
38 echo " Deleting branch: $branch"
39 git branch -D "$branch"
40 done
41 ```
42
43## Expected Behavior
44
45After executing these commands, you will:
46
47- See a list of all local branches with their status
48- Identify and remove any worktrees associated with [gone] branches
49- Delete all branches marked as [gone]
50- Provide feedback on which worktrees and branches were removed
51
52If no branches are marked as [gone], report that no cleanup was needed.
53