How to use Git worktrees for multiple branches

· Category: Git

Short answer

git worktree allows you to check out multiple branches into separate directories from a single repository.

Steps

  1. Create a worktree for a branch:
git worktree add ../repo-fix fix-branch
  1. List worktrees:
git worktree list
  1. Remove a worktree:
git worktree remove ../repo-fix
  1. Create a new branch and worktree:
git worktree add -b hotfix ../repo-hotfix main

Tips

  • Worktrees share the same .git object database, saving disk space.
  • Ideal for reviewing PRs while continuing development on your main branch.
  • You cannot check out the same branch in multiple worktrees.

Common issues

  • Uncommitted changes in one worktree do not affect others.
  • Deleting the worktree directory manually requires git worktree prune to clean up.