Most developers handle parallel work one of two ways — stash everything and switch branches, or clone the repo a second time. Both work, but both have friction. git worktree is the cleaner solution that ships with Git itself.
What it does
git worktree lets you check out multiple branches simultaneously, each in its own directory on disk. They share the same Git history and object database, so there's no duplication, no sync issues, and no separate remote to manage.
Basic usage
git worktree add ../project-hotfix hotfix-branch
You now have two working directories:
- /project — your original branch, untouched
- /project-hotfix — hotfix-branch, fully checked out and ready
Open a second terminal, cd into the new folder, and work normally. Both are live at the same time.
Practical scenarios
Production bug comes in mid-feature
Don't stash. Don't switch. Just open the hotfix worktree in a new terminal, fix it, push, close the terminal. Your feature branch is exactly as you left it.
Running tests on two branches simultaneously
Start the test suite in both worktree directories at the same time and compare output directly. Useful when you're benchmarking or verifying a fix didn't break something on another branch.
Reviewing a large PR properly
Instead of checking out the PR branch and losing your work, add it as a worktree, run the code, then remove the worktree when done.
Other commands worth knowing
List all active worktrees
git worktree list
Remove a worktree when you're done
git worktree remove ../project-hotfix
Create a worktree with a new branch (doesn't have to exist yet)
git worktree add ../experiment -b experiment-branch
One constraint
You cannot check out the same branch in two worktrees at the same time. Each worktree needs a unique branch. If you try, Git will error with a clear message.
Worth noting
git worktree has been available since Git 2.5 (released 2015). No plugins, no configuration, nothing to install. It's just there.
If you work on a codebase where context switching is frequent — multiple ongoing features, regular hotfixes, or heavy PR review load — worktrees are worth making a habit.
Top comments (0)