worktree-remove
Skill0 starsChanged 9 months agoMITView on GitHub
Removes a git worktree and optionally deletes its branch. Use for abandoned experiments or when branch is already merged. For completing work with merge, use worktree-end instead.
1 other project uses a version of this.
Adopted by
Most recently taken up by
- Joshua-Palamuttam/workbench-templatetheir own version, first seen Mar 7, 2026
Other versions1 project uses a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 1
- Joshua-Palamuttam/workbench-template★ 3same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository18 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- adr-createSkill
- dev-log-rotateSkill
- discovery-startSkill
- gather-insightSkill
- git-commitSkill
- init-projectSkill
- insight-captureSkill
- jira-startSkill
- review-implementationSkill
- session-endSkill
- session-listSkill
- session-startSkill
- team-stream-startSkill
- work-stream-startSkill
- worktree-endSkill
- worktree-listSkill
- worktree-startSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
18 rules. About 0 are common, 18 are distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈18
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 24
Must be in the main repository (not in the worktree being removed)
- Distinctive: line 41
If user didn't specify which worktree:
- Distinctive: line 43
Use AskUserQuestion to ask:
- Distinctive: line 72
Cancel: - Don't remove, go back
- Distinctive: line 73
Force remove: - Remove anyway, losing changes
- Distinctive: line 82
Check if branch has been merged to main:
- Distinctive: line 110
Keep branch: - Only remove worktree, keep branch for potential reuse
- Distinctive: line 111
Delete branch: - Remove worktree AND delete the branch
- Distinctive: line 112
Cancel: - Don't remove anything
- Distinctive: line 130
If user chose to delete branch:
- Distinctive: line 154
If there was a context file, mention:
- Distinctive: line 168
Check if path exists
- Distinctive: line 169
If not, suggest: "Worktree path not found.
- Distinctive: line 188
Uncommitted changes warning: Always check and warn before removing
- Distinctive: line 191
Force is opt-in: Never force-remove without explicit user approval
- Distinctive: line 255
Does NOT delete branch
- Distinctive: line 275
Always run from main repository, not from within a worktree
- Distinctive: line 278
After removing worktree, the branch still exists unless explicitly deleted
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Worktree Remove Skill
Safely removes a git worktree and optionally deletes its associated branch.
When to Use
Activate this skill when:
- User wants to remove/delete a worktree
- User says "remove worktree", "delete worktree", or "clean up worktree"
- User has finished work and manually merged the branch
- User wants to abandon work in a worktree
For completing work with automatic merge, use /worktree-end instead.
Prerequisites
- Must be in the main repository (not in the worktree being removed)
- Worktree should ideally have no uncommitted changes
- Branch should be merged if keeping the work
Instructions
Step 1: Get Available Worktrees
Run:
git worktree listParse output to get list of worktrees (excluding main).
Step 2: Ask Which Worktree to Remove
If user didn't specify which worktree:
Use AskUserQuestion to ask:
Question: "Which worktree do you want to remove?"
- List available worktrees as options
- Show branch name for each
- Example options:
- "../feature-auth (branch: feature-auth)"
- "../bugfix-login (branch: bugfix-login)"
Step 3: Check for Uncommitted Changes
For the selected worktree, run:
git -C "[worktree-path]" status --porcelainIf there are uncommitted changes:
- Warn user:
Warning: This worktree has uncommitted changes! Changes: - [list of changed files] These changes will be LOST if you proceed. Are you sure you want to remove this worktree? - Require explicit confirmation before proceeding
- Options:
- Cancel - Don't remove, go back
- Force remove - Remove anyway, losing changes
If clean (no uncommitted changes):
- Proceed to next step
Step 4: Check Branch Merge Status
Get the branch name from the worktree.
Check if branch has been merged to main:
git branch --merged main | grep "[branch-name]"If NOT merged:
- Warn user:
Warning: Branch "[branch-name]" has NOT been merged to main! If you delete this branch, you may lose commits. Options: 1. Remove worktree, keep branch (recommended) 2. Remove worktree AND delete branch (commits will be lost) 3. Cancel
If merged (or user doesn't care):
- Proceed to ask about branch deletion
Step 5: Ask About Branch Deletion
Use AskUserQuestion:
Question: "Do you want to delete the branch '[branch-name]' as well?"
Options:
- Keep branch - Only remove worktree, keep branch for potential reuse
- Delete branch - Remove worktree AND delete the branch
- Cancel - Don't remove anything
Step 6: Remove Worktree
Run:
git worktree remove "[worktree-path]"If fails due to uncommitted changes and user confirmed force:
git worktree remove --force "[worktree-path]"Verify removal succeeded.
Step 7: Delete Branch (if requested)
If user chose to delete branch:
If branch was merged:
git branch -d "[branch-name]"If branch was NOT merged (and user confirmed):
git branch -D "[branch-name]"Step 8: Confirm Completion
Display summary:
Worktree removed successfully!
Removed: ../[worktree-name]
Branch: [kept / deleted]
Remaining worktrees: [N]If there was a context file, mention:
Note: The worktree's context file (.claude-worktree-context.md) was removed with the worktree.Error Handling
If not in main repository:
- Detect if current directory is a worktree (not main)
- Error: "You appear to be in a worktree. Run this skill from the main repository."
If worktree doesn't exist:
- Check if path exists
- If not, suggest: "Worktree path not found. Run
git worktree pruneto clean up stale entries?"
If git worktree remove fails:
- Parse error message
- Common issues:
- Uncommitted changes: offer force option
- Path doesn't exist: suggest prune
- Locked worktree: suggest checking if VS Code is open there
- Show helpful recovery options
If branch delete fails:
-dfails if not merged: suggest-Dwith warning- Branch doesn't exist: just note it and continue
- Branch is checked out elsewhere: explain the situation
Safety Features
- Uncommitted changes warning: Always check and warn before removing
- Merge status check: Warn if branch isn't merged to prevent data loss
- Explicit confirmation: Require user confirmation for destructive actions
- Force is opt-in: Never force-remove without explicit user approval
- Branch deletion is separate: Worktree removal and branch deletion are separate decisions
Examples
Example 1: Clean Removal (Merged Branch)
User: "/worktree-remove"
Skill Actions:
- Lists worktrees:
- ../feature-auth
- ../bugfix-login
- Asks: "Which worktree?" - User selects "feature-auth"
- Checks status - clean (no uncommitted changes)
- Checks merge status - branch IS merged to main
- Asks: "Delete branch too?" - User selects "Delete branch"
- Runs:
git worktree remove "../feature-auth" - Runs:
git branch -d "feature-auth" - Confirms: "Worktree removed, branch deleted"
Example 2: Uncommitted Changes
User: "/worktree-remove feature-auth"
Skill Actions:
- Parses: worktree = "feature-auth"
- Checks status - HAS uncommitted changes:
M src/auth/mod.rs?? src/auth/new_file.rs
- Warns:
Warning: This worktree has uncommitted changes! Changes: - M src/auth/mod.rs - ?? src/auth/new_file.rs These changes will be LOST if you proceed. - Asks: "Remove anyway?" - User selects "Cancel"
- Aborts: "Cancelled. Worktree not removed."
Example 3: Unmerged Branch
User: "/worktree-remove bugfix-login"
Skill Actions:
- Finds worktree: ../bugfix-login
- Checks status - clean
- Checks merge status - branch NOT merged
- Warns:
Warning: Branch "bugfix-login" has NOT been merged to main! Options: 1. Remove worktree, keep branch (recommended) 2. Remove worktree AND delete branch 3. Cancel - User selects "Keep branch"
- Runs:
git worktree remove "../bugfix-login" - Does NOT delete branch
- Confirms: "Worktree removed, branch kept"
Example 4: Force Remove
User: "/worktree-remove"
Skill Actions:
- Lists worktrees, user selects one
- Checks status - HAS uncommitted changes
- Warns about losing changes
- User selects "Force remove"
- Runs:
git worktree remove --force "../[worktree]" - Asks about branch
- Completes removal
Notes
- Always run from main repository, not from within a worktree
- Uncommitted changes are permanently lost when force-removing
- Keeping branches is safer; they can be deleted later
- After removing worktree, the branch still exists unless explicitly deleted
git worktree prunecan clean up stale worktree entries
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

