Black Friday sale: 30% off Pro and Unlimited, until 22 December

How to move a Git worktree to a new folder

Move a linked Git worktree with its branch and local edits intact, repair it after a manual move, and handle worktrees with submodules.

You have a checkout open for a fix and want it somewhere else: a different drive, a tidier folder, a name that matches the task. Moving the folder with Finder or mv works, but Git then has to be told. git worktree move does both in one step and keeps the branch and your edits.

Check what’s in the worktree first

In this example the main checkout is ~/code/acme/web and the worktree to move is ~/code/acme/web-checkout-fix. Run these from the main checkout.

git worktree list
git -C ../web-checkout-fix status --short --branch --ignored --untracked-files=all
~/code/acme/web               b3cac63 [main]
~/code/acme/web-checkout-fix  b3cac63 [checkout-fix]
## checkout-fix
 M src/cart.js
?? notes.txt
!! local-cache.txt

Note the branch and the edits: M is a changed tracked file, ?? an untracked one and !! an ignored one. You’ll compare against this after the move. The main checkout can’t be moved this way, only linked worktrees.

Move it

git worktree move ../web-checkout-fix ../web-cart-fix

Git moves the folder and updates its own record of where it lives. The branch isn’t touched, and neither are your edits.

Check the result

git worktree list
git -C ../web-cart-fix status --short --branch --ignored --untracked-files=all
~/code/acme/web               b3cac63 [main]
~/code/acme/web-cart-fix      b3cac63 [checkout-fix]
## checkout-fix
 M src/cart.js
?? notes.txt
!! local-cache.txt

The same branch, the same commit and the same three lines of status mean nothing was lost. If the worktree is locked, Git refuses with cannot move a locked working tree. Find out why it was locked, and unlock it with git worktree unlock ../web-checkout-fix before you try again.

Repair a worktree you moved by hand

If you already moved the folder yourself, Git still points at the old path.

mv ../web-hotfix ../web-urgent
git worktree list

The list now shows prunable for the old path.

~/code/acme/web           b3cac63 [main]
~/code/acme/web-hotfix    b3cac63 [hotfix] prunable

Don’t run git worktree prune here: it would clear the record of a worktree that still exists. Tell Git the new location from the main checkout instead.

git worktree repair ../web-urgent
repair: gitdir incorrect: /Users/dev/code/acme/web/.git/worktrees/web-hotfix/gitdir

Check the list again.

git worktree list
~/code/acme/web           b3cac63 [main]
~/code/acme/web-urgent    b3cac63 [hotfix]

Check the status in the new folder as above. Your branch and edits are in the folder, so they moved with it.

Worktrees with submodules

Git refuses to move a worktree that contains submodules, even with --force.

fatal: working trees containing submodules cannot be moved or removed

You have two options. If the worktree holds nothing you need to keep, remove it and add a fresh one in the new place. See how to clean up Git worktrees for what removal deletes. If it holds work in progress, move the folder by hand, then repair it.

mv ../web-cart ../web-cart-fix
git worktree repair ../web-cart-fix
cd ../web-cart-fix
git status

The repair fixes the worktree, but the submodule can still point at the old folder, and git status fails with cannot chdir. Re-link it.

git submodule update --init
git status --short --branch

An edited submodule shows as m (modified content), and git -C libs/ui diff --stat shows the edits are still there. This checks out the commit the branch records for the submodule. If you’ve committed inside the submodule, note that commit first and check it afterwards.

Keep an eye on every worktree

push& (Pushand) groups linked worktrees under their repository, so a moved worktree still counts with the rest, as long as the repository is watched. See how push& groups worktrees and how it tracks unpushed commits across worktrees. Once your work is pushed, clean up the ones you’re done with.

More Git how-tos