Skip to content

Improve deleting worktrees and their branches - #5748

Merged
stefanhaller merged 6 commits into
masterfrom
worktree-deletion-ux
Jul 3, 2026
Merged

Improve deleting worktrees and their branches#5748
stefanhaller merged 6 commits into
masterfrom
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 stefanhaller added the enhancement New feature or request label Jul 1, 2026
@stefanhaller
stefanhaller force-pushed the worktree-deletion-ux branch from 1e898ff to e305eb2 Compare July 2, 2026 09:09
@stefanhaller
stefanhaller force-pushed the worktree-creation-ux branch 2 times, most recently from 4737b7e to 7a67cea Compare July 3, 2026 16:53
Base automatically changed from worktree-creation-ux to master July 3, 2026 17:02
stefanhaller and others added 6 commits July 3, 2026 19:04
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>
@stefanhaller
stefanhaller force-pushed the worktree-deletion-ux branch from e305eb2 to 0aed44c Compare July 3, 2026 17:05
@stefanhaller
stefanhaller enabled auto-merge July 3, 2026 17:05
@stefanhaller
stefanhaller merged commit 0ecced9 into master Jul 3, 2026
13 checks passed
@stefanhaller
stefanhaller deleted the worktree-deletion-ux branch July 3, 2026 17:07
tmeijn pushed a commit to tmeijn/dotfiles that referenced this pull request Jul 9, 2026
This MR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [jesseduffield/lazygit](https://github.com/jesseduffield/lazygit) | minor | `v0.62.2` → `v0.63.0` |

MR created with the help of [el-capitano/tools/renovate-bot](https://gitlab.com/el-capitano/tools/renovate-bot).

**Proposed changes to behavior should be submitted there as MRs.**

---

### Release Notes

<details>
<summary>jesseduffield/lazygit (jesseduffield/lazygit)</summary>

### [`v0.63.0`](https://github.com/jesseduffield/lazygit/releases/tag/v0.63.0)

[Compare Source](jesseduffield/lazygit@v0.62.2...v0.63.0)

<!-- Release notes generated using configuration in .github/release.yml at v0.63.0 -->

#### What's Changed

##### Enhancements 🔥

- Add direnv support by [@&#8203;stefanhaller](https://github.com/stefanhaller) in [#&#8203;5660](jesseduffield/lazygit#5660)
- Improve cycling through multiple pagers by [@&#8203;stefanhaller](https://github.com/stefanhaller) in [#&#8203;5678](jesseduffield/lazygit#5678)
- Detect external repo changes via background polling by [@&#8203;stefanhaller](https://github.com/stefanhaller) in [#&#8203;5662](jesseduffield/lazygit#5662)
- Make the side panels configurable by [@&#8203;stefanhaller](https://github.com/stefanhaller) in [#&#8203;5702](jesseduffield/lazygit#5702)
- Add a global keybinding for editing the config file by [@&#8203;stefanhaller](https://github.com/stefanhaller) in [#&#8203;5728](jesseduffield/lazygit#5728)
- Improve resolving non-textual and submodule merge conflicts by [@&#8203;stefanhaller](https://github.com/stefanhaller) in [#&#8203;5735](jesseduffield/lazygit#5735)
- Auto-dismiss the continue-rebase prompt when it becomes stale by [@&#8203;stefanhaller](https://github.com/stefanhaller) in [#&#8203;5758](jesseduffield/lazygit#5758)
- Support custom pagers and passphrase prompts on Windows by [@&#8203;stefanhaller](https://github.com/stefanhaller) in [#&#8203;5740](jesseduffield/lazygit#5740)
- Make creating worktrees simpler and less error-prone by [@&#8203;stefanhaller](https://github.com/stefanhaller) in [#&#8203;5741](jesseduffield/lazygit#5741)
- Improve deleting worktrees and their branches by [@&#8203;stefanhaller](https://github.com/stefanhaller) in [#&#8203;5748](jesseduffield/lazygit#5748)
- Allow overriding the platform used for default keybindings by [@&#8203;stefanhaller](https://github.com/stefanhaller) in [#&#8203;5671](jesseduffield/lazygit#5671)
- Add `gui.shrinkSidePanelsToContent` option by [@&#8203;stefanhaller](https://github.com/stefanhaller) in [#&#8203;5754](jesseduffield/lazygit#5754)
- Show renamed files in the custom patch builder by [@&#8203;stefanhaller](https://github.com/stefanhaller) in [#&#8203;5759](jesseduffield/lazygit#5759)

##### Fixes 🔧

- Fix unstaging a submodule with dirty content by [@&#8203;stefanhaller](https://github.com/stefanhaller) in [#&#8203;5666](jesseduffield/lazygit#5666)
- Fix coloring of wrapped delta lines by [@&#8203;stefanhaller](https://github.com/stefanhaller) in [#&#8203;5711](jesseduffield/lazygit#5711)
- Fix Files Panel artefacts during rebase commands by [@&#8203;stefanhaller](https://github.com/stefanhaller) in [#&#8203;5661](jesseduffield/lazygit#5661)
- Keep selected commits stable across refreshes by [@&#8203;stefanhaller](https://github.com/stefanhaller) in [#&#8203;5717](jesseduffield/lazygit#5717)
- Fix quoting of shell commands on Windows by [@&#8203;stefanhaller](https://github.com/stefanhaller) in [#&#8203;5704](jesseduffield/lazygit#5704)
- Silently consume unrecognized or malformed escape sequences by [@&#8203;stefanhaller](https://github.com/stefanhaller) in [#&#8203;5738](jesseduffield/lazygit#5738)
- Don't include common ancestor when picking "both" for a conflict in diff3 style by [@&#8203;stefanhaller](https://github.com/stefanhaller) in [#&#8203;5747](jesseduffield/lazygit#5747)

##### Maintenance ⚙️

- Some fixes to our infrastructure by [@&#8203;stefanhaller](https://github.com/stefanhaller) in [#&#8203;5705](jesseduffield/lazygit#5705)
- Restructure the `just` recipes for running integration tests by [@&#8203;stefanhaller](https://github.com/stefanhaller) in [#&#8203;5720](jesseduffield/lazygit#5720)
- Fix flaky TestNewCmdTaskInstantStop test by [@&#8203;stefanhaller](https://github.com/stefanhaller) in [#&#8203;5743](jesseduffield/lazygit#5743)
- Bump golang.org/x/sync from 0.20.0 to 0.21.0 by [@&#8203;dependabot](https://github.com/dependabot)\[bot] in [#&#8203;5684](jesseduffield/lazygit#5684)
- Bump golang.org/x/sys from 0.45.0 to 0.46.0 by [@&#8203;dependabot](https://github.com/dependabot)\[bot] in [#&#8203;5685](jesseduffield/lazygit#5685)
- Bump github.com/sahilm/fuzzy from 0.1.2 to 0.1.3 by [@&#8203;dependabot](https://github.com/dependabot)\[bot] in [#&#8203;5706](jesseduffield/lazygit#5706)
- Bump actions/cache from 5 to 6 by [@&#8203;dependabot](https://github.com/dependabot)\[bot] in [#&#8203;5722](jesseduffield/lazygit#5722)
- Bump actions/checkout from 6 to 7 by [@&#8203;dependabot](https://github.com/dependabot)\[bot] in [#&#8203;5723](jesseduffield/lazygit#5723)
- Bump goreleaser/goreleaser-action from 7.2.2 to 7.2.3 by [@&#8203;dependabot](https://github.com/dependabot)\[bot] in [#&#8203;5745](jesseduffield/lazygit#5745)
- Bump golangci/golangci-lint-action from 9.2.0 to 9.3.0 by [@&#8203;dependabot](https://github.com/dependabot)\[bot] in [#&#8203;5746](jesseduffield/lazygit#5746)
- Bump golang.org/x/net from 0.47.0 to 0.55.0 by [@&#8203;dependabot](https://github.com/dependabot)\[bot] in [#&#8203;5752](jesseduffield/lazygit#5752)
- Pin gofumpt version to 0.9.2 by [@&#8203;stefanhaller](https://github.com/stefanhaller) in [#&#8203;5753](jesseduffield/lazygit#5753)
- Fix a few flaky tests by [@&#8203;stefanhaller](https://github.com/stefanhaller) in [#&#8203;5756](jesseduffield/lazygit#5756)

##### I18n 🌎

- Update translations from Crowdin by [@&#8203;stefanhaller](https://github.com/stefanhaller) in [#&#8203;5760](jesseduffield/lazygit#5760)

##### Performance Improvements 📊

- Prevent staging from becoming slower over time by [@&#8203;stefanhaller](https://github.com/stefanhaller) in [#&#8203;5712](jesseduffield/lazygit#5712)

**Full Changelog**: <jesseduffield/lazygit@v0.62.2...v0.63.0>

</details>

---

### Configuration

📅 **Schedule**: (UTC)

- Branch creation
  - At any time (no schedule defined)
- Automerge
  - At any time (no schedule defined)

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever MR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this MR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box

---

This MR has been generated by [Mend Renovate](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0My4yNTYuMCIsInVwZGF0ZWRJblZlciI6IjQzLjI1Ni4wIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJSZW5vdmF0ZSBCb3QiLCJhdXRvbWF0aW9uOmJvdC1hdXRob3JlZCIsImRlcGVuZGVuY3ktdHlwZTo6bWlub3IiXX0=-->
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.

Remove worktree and branch at the same time

1 participant