Skip to content

Improve deleting worktrees and their branches#5748

Open
stefanhaller wants to merge 6 commits into
worktree-creation-uxfrom
worktree-deletion-ux
Open

Improve deleting worktrees and their branches#5748
stefanhaller wants to merge 6 commits into
worktree-creation-uxfrom
worktree-deletion-ux

Conversation

@stefanhaller

Copy link
Copy Markdown
Collaborator

This PR improves three rough edges around deleting worktrees and the branches checked out in them:

  • Deleting a branch that's checked out in another worktree now actually deletes the branch. The menu used to offer to remove or detach the worktree but then stop there, leaving behind the very branch you asked to delete. Both actions now delete the branch afterwards, and the labels say so ("Remove worktree and delete branch" / "Detach worktree and delete branch"). The old "Switch to worktree" entry is dropped — it's not a useful option in the context of deleting a branch.

  • A branch's local branch, remote branch, and worktree can be deleted in one step. Picking "Delete local and remote branch" for a single branch that's checked out in another worktree used to fail with a confusing "select them one by one" error (which only makes sense for a multi-selection). It now goes through the same worktree menu, with labels that make clear the remote is deleted too.

  • Pressing d on a worktree can delete its branch. The plain confirmation becomes a menu: "Remove worktree", "Remove worktree and delete branch", and "Remove worktree and delete local and remote branch".

Throughout, the explicit menu choice acts as the confirmation, so the separate "Are you sure you want to remove worktree?" prompt is gone; the dirty-worktree force prompt and the not-fully-merged warning still show up when relevant.

Closes #5205.

stefanhaller and others added 6 commits July 1, 2026 12:51
Pull the merged-check-and-force-warning step and the actual git deletion
out of ConfirmLocalDelete and ConfirmLocalAndRemoteDelete into helpers, so
that the upcoming worktree-aware delete flows can reuse them instead of
duplicating the logic. No behavior change.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Split the actual worktree removal out of the confirmation in Remove into a
non-confirming helper, and give both Remove and Detach an optional `then`
continuation that runs after a successful removal in place of the default
refresh. Upcoming flows need to delete the worktree's branch once the worktree
is out of the way; threading a continuation through (rather than the caller
firing branch deletion independently) keeps it ordered after the git command
that actually frees the branch. No behavior change yet.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
When you delete a local branch that's checked out in another worktree, the
menu offered to remove or detach the worktree but then stopped there, leaving
the branch you asked to delete still around. Now both actions delete the branch
afterwards, and the labels say so ("Remove worktree and delete branch" /
"Detach worktree and delete branch") to avoid surprises.

Also drop the "Switch to worktree" item: switching abandons the delete the user
asked for, and it's already reachable by checking out the branch or via the
worktrees panel. And drop the now-redundant "remove worktree?" confirmation:
the explicit menu pick is the confirmation (the dirty-worktree force prompt and
the unmerged-branch warning still appear when relevant).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Picking "Delete local and remote branch" for a single branch that's checked
out in another worktree used to fail with "Some of the selected branches are
checked out by other worktrees. Select them one by one to delete them." That
message only makes sense for a multi-selection; for a single branch there's no
reason we can't remove the worktree and delete both the local and remote branch
in one go. Route that case through the same worktree menu as the local-only
delete, with labels that spell out that the remote goes too. The multi-select
error stays for actual multi-selections.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Pressing `d` on a worktree only ever removed the worktree, leaving its branch
behind even though deleting it too is often what you want. Turn the confirmation
into a menu: "Remove worktree", "Remove worktree and delete branch", and "Remove
worktree and delete local and remote branch". The branch-deleting items come
after the plain removal (they do more harm if picked by accident); both are
greyed out for a detached-HEAD worktree, and the local-and-remote one is also
greyed when the branch has no upstream. The plain menu pick is the confirmation,
so the standalone "remove worktree?" prompt is gone (and its now-dead
translation string with it); the dirty-worktree force prompt and the
unmerged-branch warning still appear when relevant.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant