Remove a git worktree and optionally delete the branch
Safely removes a git worktree with pre-removal checks and optional branch cleanup.
/plugin marketplace add notedit/happy-coding-agent/plugin install notedit-happy-coding-agent@notedit/happy-coding-agentWorktree path or branch name (e.g., "../my-project-feature" or "feature/login")git/Safely remove a worktree and clean up associated resources.
Actions:
git worktree list
Show table:
| Path | Branch | Status |
|---|---|---|
| /path/to/main | main | (bare) |
| /path/to/feature | feature/x | clean |
If $ARGUMENTS provided:
If empty:
Prevent removing main worktree.
Check for uncommitted changes:
cd <worktree-path> && git status
If changes exist:
Check for unpushed commits:
git log origin/<branch>..<branch> --oneline
If unpushed: warn user and ask to push first.
Standard removal:
git worktree remove <path>
Force removal (if dirty):
git worktree remove --force <path>
Ask user: Delete the branch too?
If yes, check merge status:
git branch --merged main | grep <branch>
Delete branch:
git branch -d <branch>git branch -D <branch>Delete remote branch (optional):
git push origin --delete <branch>
Clean up:
git worktree prune
Show final worktree list.
| Check | Action |
|---|---|
| Uncommitted changes | Require user decision |
| Unpushed commits | Warn and confirm |
| Unmerged branch | Require force confirm |
| Main worktree | Block removal |