Worktree Done
Remove the current git worktree, switch the main checkout to the base branch, and delete the feature branch.
Use this when finishing work that was started with the worktree skill (or /worktree).
When to apply
Cleaning up after work done inside a worktree. Do not apply from the main checkout — that is branch-done.
Steps
- Verify the current directory is inside a worktree (not the main checkout).
- Compare
git rev-parse --git-dirandgit rev-parse --git-common-dir. If they are equal, this is the main checkout — stop and tell the user to use thebranch-doneskill instead.
- Compare
- Record the current worktree path (
git rev-parse --show-toplevel) and current branch name (git rev-parse --abbrev-ref HEAD). - Determine the base branch:
- Try
git symbolic-ref refs/remotes/origin/HEADand strip therefs/remotes/origin/prefix. - If that fails, use the first of
dev,main,masterthat exists locally (git show-ref --verify --quiet refs/heads/<name>). - If none exist, stop and ask the user which branch is the base.
- Try
- If the recorded branch is the base branch (or is itself
dev,main, ormaster), stop and notify the user. - Check for uncommitted changes (
git status --porcelain). If any exist, stop and report them — do not force removal. - Resolve the main checkout path: parse
git worktree list --porcelainand take the firstworktree <path>entry. cdinto the main checkout path.- Checkout the base branch and pull latest:
git checkout <base branch> && git pull - Remove the worktree:
git worktree remove <recorded worktree path> - Delete the feature branch locally:
git branch -D <recorded branch> - Confirm in one line:
Worktree removed → back on <base branch>, deleted <branch>
Guardrails
- Never run
git worktree remove --force. If removal fails due to dirty state, stop and report. - Never delete the base branch or other protected branches (
main,master,dev). - Do not run this from the main checkout — that is
branch-done's job.