Hooks, LFS & submodulesAlways fixable

Check out two branches at once with git worktree

How do I work on two branches at the same time without stashing or re-cloning?

If you’re seeing this error

fatal: '<branch>' is already checked out at '<path>'
fatal: '<path>' is not a working tree

You’re in the right place — the fix is below.

Short answer

git worktree add ../hotfix main gives you a second folder checked out to a different branch, sharing the same .git object store. No stashing, no second clone, no waiting for your build to reinstall. When you're done, git worktree remove ../hotfix cleans it up.

quick fix
git worktree add ../myrepo-hotfix main
cd ../myrepo-hotfix

A second working directory on a different branch, in one command

Does this match your situation?

  • You need to review or hotfix another branch without disturbing half-finished work.
  • 'fatal: '<branch>' is already checked out at '<path>''
  • You keep stashing, switching, unstashing and losing your place.
  • Switching branches forces a full rebuild or a dependency reinstall every time.

Step-by-step fix

  1. Add a second working directory

    One command creates a new folder checked out to the branch you name. It is a full working tree — you can build, test, commit and push from it exactly as normal.

    step 1
    git worktree add ../myrepo-hotfix main
    
    # create a brand-new branch in the new folder:
    git worktree add -b hotfix/login ../myrepo-hotfix origin/main
    
  2. See what you have

    Worktrees are easy to forget about. list shows every one, its path, its commit and its branch — including any left behind on a drive you have since unplugged.

    step 2
    git worktree list
    
  3. Understand the one-branch-per-worktree rule

    Git refuses to check the same branch out twice, because two folders committing to one branch would fight over the same ref. The error names the folder that already has it, which is usually all you need.

    step 3
    git worktree list        # find who holds the branch
    # work on it there, or make a new branch instead:
    git worktree add -b hotfix-2 ../another main
    

    --force overrides the check. Do it only if you understand that both checkouts will be moving the same branch pointer.

  4. Inspect a detached commit without touching your branch

    A detached worktree is the cleanest way to look at an old tag or a colleague's commit: nothing about your current branch or working directory changes.

    step 4
    git worktree add --detach ../inspect v1.4.0
    
  5. Remove it when you're finished

    remove deletes the folder and its administrative files. Deleting the folder by hand instead leaves a stale entry, which prune clears.

    step 5
    git worktree remove ../myrepo-hotfix
    
    # if you already deleted the folder manually:
    git worktree prune
    

Why this works

A clone's real content lives in .git — the object database plus the refs — and the files you edit are just one checkout of it. A worktree separates those two ideas: it creates another checkout backed by the same object database, holding only a small file pointing back at the original .git. That is why adding one is nearly instant even on a huge repository and why it costs almost no extra disk, unlike a second clone which duplicates every object and starts with its own detached history, its own remotes and its own stale reflog. The single restriction — one branch checked out at a time — exists because a branch is a single pointer, and two working trees advancing it independently would silently lose commits.

If that didn’t work

  • 'is not a working tree' usually means the folder was deleted by hand: run git worktree prune.
  • A worktree on an unplugged external drive blocks removal — git worktree prune clears the record.
  • Locked worktrees need git worktree unlock <path> before they can be removed.
  • Submodules are not shared between worktrees; run git submodule update --init inside the new one.

How to stop it happening again

  • Keep worktrees as siblings of the main folder (../repo-hotfix) so they never end up committed by accident.
  • Run git worktree list before you go hunting for a branch Git says is already checked out.
  • Use git worktree remove rather than deleting folders, so no stale records accumulate.
  • Prefer a worktree over a second clone — the reflog, remotes and objects stay in one place.

Commands used in this guide

git worktree

Check out several branches into separate folders from one repository.

git switch

Move to another branch - the modern, safer half of git checkout.

git branch

List, create, rename and delete branches.

git stash

Park uncommitted work temporarily so you can do something else.

git clone

Copy a remote repository, its full history and its branches, onto your machine.

Still stuck?

Search the full command reference and every other rescue guide — there are 76 of them, covering everything from detached HEAD to force-push disasters.

Browse all guides →

Frequently asked questions

What does 'fatal: branch is already checked out at' mean?

Another worktree has that branch checked out, and Git allows a branch in only one working tree at a time so two folders cannot advance the same pointer independently. Run git worktree list to see which folder holds it, and either work there or create a different branch.

Is a worktree better than cloning the repository twice?

Usually, yes. A worktree shares the object database, so it is near-instant to create, costs little disk, and gives you one reflog, one set of remotes and one place where every commit lands. A second clone duplicates everything and its history drifts out of step with the original.

Do worktrees share stashes and branches?

They share branches, tags, remotes, objects and the stash, because all of those live in the shared .git. What each worktree keeps to itself is its own HEAD, index and working files — which is exactly what lets you have two different branches checked out at once.

How do I delete a Git worktree?

git worktree remove <path>, which deletes the folder and its bookkeeping. If you already deleted the folder by hand, git worktree prune clears the stale record. Use --force when the worktree has uncommitted changes you are willing to lose.

Do worktrees work with submodules and hooks?

Hooks are shared, since core.hooksPath and .git/hooks live in the common directory — but a per-worktree config set with --worktree is not. Submodules are not automatically populated, so run git submodule update --init inside each new worktree.

Related rescue guides

← All Git Rescue guides