Today I learned about git worktree — a feature that lets you check out multiple branches simultaneously in separate directories.
The problem
You’re deep in a feature branch. Someone asks you to review a PR on main. Normally you’d stash your work, switch branches, review, switch back, pop stash. Annoying.
The solution
# Create a new worktree for the main branch
git worktree add ../project-main main
# Now you have two directories:
# ../project/ → your feature branch
# ../project-main/ → main branch
# When done, clean up
git worktree remove ../project-main
That’s it. No stashing. No context switching. Two branches, two directories, same repo.
When it’s useful
- Code reviews while working on something else
- Running tests on one branch while developing on another
- Comparing behavior across branches side by side
Small tool, big quality-of-life improvement.