Git Cheat Sheet · Worktrees

Delete a worktree

git worktree remove <folder>

git worktree remove <folder> deletes the folder and its reference in the repository. The branch and its commits stay: you can reopen it later, or delete it separately with git branch -d.

What it does

Deletes the folder and its reference in the repository. The branch and its commits remain: you can reopen it later, or delete it separately.

A use case

Your fix is merged: the folder is no longer needed, and its branch can be deleted afterwards.

Warning: All the folder's content is erased, including uncommitted changes and untracked or ignored files. First commit or copy what you want to keep; a stash is another option, since it is shared between worktrees.

On the command line

git worktree remove <folder>
Deletes a clean worktree. Git refuses if there are changes left.
git worktree remove --force <folder>
Deletes it anyway: uncommitted changes are lost.
git branch -d <branch>
Then deletes the branch, if it is no longer needed.

In Merathon

  1. Open another worktree: the displayed one cannot be deleted, nor can the main one.
  2. Right-click the worktree → "Delete…".
  3. The confirmation shows how many files would be lost; the worktree's tab then closes.

Frequently asked questions

Are my commits lost?

No: they belong to the repository and stay on the branch. Only the folder's uncommitted files go away.

Can I delete the main worktree?

No: it is the original folder, which contains the repository. Git refuses.

I deleted the folder by hand. Is that a problem?

No, but the repository keeps its reference and its branch is still considered checked out: git worktree prune fixes it.

See also