Git Cheat Sheet · Worktrees

Move or lock a worktree

git worktree move <folder> <new-folder> ; git worktree lock <folder>

git worktree move moves a worktree's folder while keeping the link with the repository. git worktree lock protects it from deletion and cleanup, for example if it is on an external drive. git worktree unlock lifts the protection.

What it does

move moves the folder while keeping the link with the repository. lock protects it from deletion and cleanup, for example if it is on an external drive; git worktree unlock removes the protection.

A use case

Your worktree is on a USB stick that is often unplugged: locked, it will not be cleaned up by mistake.

Warning: Do not move the folder by hand: the link would break. Use git worktree move.

On the command line

git worktree move <folder> <new-folder>
Moves the worktree.
git worktree lock --reason "external drive" <folder>
Locks the worktree, noting the reason.
git worktree unlock <folder>
Lifts the lock.
git worktree repair <folder>
Restores the link after a move done by hand.

In Merathon

  1. These operations are done on the command line: open the bottom panel (Ctrl+J) then the "Terminal" tab.
  2. A locked worktree is marked "locked" and cannot be deleted from the application.

Frequently asked questions

Can I move the folder by hand?

Better not, because the link would be broken. If it is already done, git worktree repair <folder> restores it from the main repository.

Can I move the main worktree?

Not with git worktree move, which also refuses worktrees containing submodules.

See also