Stop stashing — use a second worktree
Handle the urgent bug fix without disturbing the half-finished work on your current branch.
You’re mid-feature, nothing compiles, and something urgent lands. The reflex is
git stash — which works, until you forget what’s in the stack.
git worktree gives you a second working directory backed by the same
repository. Two branches checked out at once, one clone on disk:
git worktree add ../myrepo-hotfix hotfix/login-500
That’s a real directory you can cd into, open in a second editor window, and
run tests in — while your feature branch sits untouched exactly as you left it.
To start from a new branch instead of an existing one:
git worktree add -b hotfix/login-500 ../myrepo-hotfix origin/main
When you’re done:
git worktree list # see everything currently checked out
git worktree remove ../myrepo-hotfix
Worth knowing
- Git won’t let you check out the same branch in two worktrees at once. That’s a feature — it’s what stops you fighting yourself.
node_modules,.venvand other ignored build artefacts aren’t shared. Each worktree needs its own install.- If you delete a worktree directory manually,
git worktree prunecleans up the stale metadata.
The real unlock is parallelism: a long test suite can run in one worktree while you keep typing in the other.