Git Cheat Sheet · Worktrees

Find a branch's worktree

git worktree list

A branch can only be checked out in one worktree at a time: otherwise, a commit in one would move the branch under the other's files. git worktree list shows where it is.

What it does

A branch can only be checked out in one worktree at a time: otherwise, a commit in one would move the branch under the other's files. Elsewhere, it can therefore be neither checked out, nor advanced, nor deleted.

A use case

The checkout of main is refused because main is already checked out in your main folder: just go work there.

On the command line

git worktree list
Shows the branch checked out in each folder.
git worktree list --porcelain
The same list, in a format easy for a script to read.
git -C <folder> switch <other-branch>
Frees the branch by switching branches in the other worktree.

In Merathon

  1. Right-click the branch: "Checkout" is grayed out with the note "Checked out in another worktree".
  2. Choose "Open its worktree" to go there.

Frequently asked questions

Why can my branch not be deleted?

It is checked out in a worktree. Delete that worktree or switch branches in it, then run the deletion again.

The worktree no longer exists, but the branch stays blocked. What should I do?

The repository keeps its reference: git worktree prune removes it and frees the branch.

See also