Skip to content
Versora

Manual

Worktrees

Remove, lock and unlock worktrees

6 min read

On this page

Once the task is done, the worktree can go. Versora first checks what would be lost: uncommitted changes, an operation stopped midway, commits that only exist on that branch and unpushed commits. When something would be lost, it asks you to type a name to confirm.

You can also lock a worktree. A locked worktree isn't removed or pruned by git, not even by mistake. That's useful for folders on an external or network drive, which sometimes aren't connected.

Remove a worktree

Where to find it

  • A worktree's menu (the WORKTREES section, or its WIP row in the graph):
    • Remove this worktree…;
    • Remove worktree and delete branch ‹branch›… (only when the worktree is on a branch).
  • The Remove this worktree… button in the right panel, with another worktree's WIP row selected.
  • The menu of the branch that's checked out in another worktree: Remove this branch's worktree… and Remove worktree and delete branch ‹branch›….
  • Palette (Ctrl+P), in a linked worktree's tab: "Remove this worktree (‹folder›)…". The app leaves the worktree before removing it.

Step by step

  1. Choose one of the entries. The Remove the worktree ‹folder› window shows "Checking what's in this worktree…" and then the worktree's branch.
  2. Under What to remove, choose:
    • Just the worktree (the folder): "the branch ‹branch› stays";
    • The worktree and the local branch ‹branch›;
    • The worktree, the local branch ‹branch› and the remote branch ‹remote›/‹branch›: only shows up when the branch tracks a remote branch that exists.
  3. Read the list of what happens. It may include:
    • "N uncommitted changes will be lost:", with the files (up to 12, then "and N more");
    • "There's a ‹operation› stopped halfway in this worktree: it will be abandoned.";
    • "The worktree has populated submodules: git only removes it when forced.";
    • "The branch ‹branch› has N commits that aren't in any other branch, remote or tag. They stay reachable only through Ctrl+Z or the reflog:", with the commits;
    • "Every commit of the branch ‹branch› is in another branch, remote or tag: nothing is lost by deleting it.";
    • "N commits haven't been pushed to ‹upstream› yet.";
    • "The branch ‹remote›/‹branch› will be deleted on the server. Ctrl+Z doesn't undo that.";
    • "No uncommitted changes: nothing is lost by removing the folder.";
    • "The folder no longer exists: only the worktree's record leaves the repository."
  4. If something would be lost, the window asks To confirm, type ‹name›. The name is the branch's when commits would be lost, or the worktree folder's in the other cases.
  5. Click Remove worktree, Remove worktree and branch or Remove and delete on the server, depending on the choice.
  6. The app leaves the worktree's tab, if it's the active one (it goes to another tab of the same repository or opens the main worktree), and closes its tab along with its terminals. With a program running in a terminal of that tab, it asks first, as when closing a tab.
  7. The notice confirms: "Worktree ‹folder› removed.", "Worktree ‹folder› and branch ‹branch› removed." or "Worktree ‹folder› removed and branch ‹branch› deleted here and on the server."
OptionWhat it doesDefault
Just the worktree (the folder)Deletes the folder and the worktree's record. The branch stays.Selected in "Remove this worktree…"
The worktree and the local branchAlso deletes the local branch.Selected in "Remove worktree and delete branch…"
The worktree, the local branch and the remote branchAlso deletes the branch on the server (a deletion push).—

What Versora does in git

bash
# the folder and the record (--force only when there are changes, an operation or submodules)
git worktree remove [--force] ../loja-web-wt

# with the local branch
git branch -D fix/erro-no-login

# with the remote branch
git push origin --delete fix/erro-no-login

Right before running, the app checks again that the worktree is on the same commit and the same branch as when it was checked. The remote branch is only deleted after the local one is gone.

How to undo

  • Ctrl+Z brings the local branch back, on the same commit ("Remove worktree ‹folder› and branch ‹branch›").
  • The worktree's folder and what only existed in it don't come back: the uncommitted changes and the ignored files (such as .env). The window reminds you of that: "Ctrl+Z brings the local branch back; the worktree folder and its ignored files (like .env) don't come back."
  • The branch deleted on the server doesn't come back with Ctrl+Z. After recovering the local branch, push it again.
  • To get the folder back, create a new worktree from the recovered branch.

Caveats and messages

  • "This is the repository's main folder: it can't be removed as a worktree.": only linked worktrees can be removed.
  • "This worktree is locked. Unlock it to remove it." (or with the reason): the window comes with the Unlock worktree button.
  • "Couldn't leave this worktree: open another folder of the repository before removing it.": the active tab is the worktree and the app didn't find another folder of the repository to open.
  • "This worktree is the folder open in this tab: leave it before removing it.": the same case, coming from git.
  • "The worktree changed since it was checked (another commit or another branch). Check it again before removing it.": someone touched the folder after the check. Open the window again.
  • "The worktree was removed from the repository, but the folder "‹folder›" couldn't be fully deleted (a file is open in another program: editor, terminal, server). Close those programs and delete the folder.": the record is gone, but part of the folder was left. Close the programs and delete it in File Explorer.
  • "The worktree was removed, but the branch ‹branch› couldn't be deleted: ‹error›" and "The worktree and the local branch were removed, but ‹remote›/‹branch› couldn't be deleted on the server: ‹error›": the earlier part worked; deal with the rest by hand.
  • "The branch doesn't track an existing remote branch: there's nothing to delete on the server."

Caution

With the remote branch option, the branch disappears from the server for the whole team, and a merge request opened from it is left without its source branch. Only use it when the work has already gone into the target branch.

A worktree whose folder is missing

If a worktree's folder was deleted or moved outside the app (or is on a disconnected drive), the WORKTREES section shows "folder missing" on its row. The actions that depend on the folder are disabled. Use Remove this worktree… to clean up the record: the window says "The folder no longer exists: only the worktree's record leaves the repository."

If the folder is on a drive that's sometimes disconnected, lock the worktree (below) so git doesn't delete the record on its own.

Lock and unlock a worktree

Where to find it

  • A worktree's menu (the WORKTREES section or its WIP row): Lock worktree… or, if it's already locked, Unlock worktree.
  • In the removal window of a locked worktree: the Unlock worktree button.

Step by step

  1. Right-click the worktree and choose Lock worktree….
  2. The Lock the worktree ‹folder› window explains: "A locked worktree isn't removed or pruned by git, not even by mistake. Useful for folders on external or network drives."
  3. In Reason (optional), write why (for example "external drive"). The reason shows up in the padlock's tooltip, in the WORKTREES section.
  4. Click Lock. The notice says "Worktree ‹folder› locked."
  5. To unlock, choose Unlock worktree in the same menu ("Worktree ‹folder› unlocked.").

What Versora does in git

bash
git worktree lock --reason "external drive" ../loja-web-wt
git worktree unlock ../loja-web-wt

How to undo

Locking and unlocking don't go into Ctrl+Z. One undoes the other.

There's no setting of its own for removing or locking.

See also