You have a pull request open. Tests are failing. Your PM asks you to fix a production bug — right now.
You have two choices:
Stash your current work, switch branches, fix the bug, switch back, unstash
Clone the entire repo again to a separate folder
Both are terrible. But there's a third option most developers don't know about.
What Are Git Worktrees?
A worktree is a linked copy of your repository that lets you check out a different branch in a separate directory — without switching your current working tree.
# While working on feature/login, create a worktree for a hotfix git worktree add ../project-hotfix fix/production-crash
# Fix the bug in a SEPARATE directory cd ../project-hotfix # ... make changes, commit, push ... cd ../project
# You're STILL on feature/login. Nothing stashed, nothing lost.
Enter fullscreen mode
Exit fullscreen mode
No stashing. No cloning. No context switching overhead.
Why This Is a Superpower
1.…