You're Using Git Wrong — How Worktrees Will Change Your Workflow Forever
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. No stashing. No cloning. No context switching overhead. Why This Is a Superpower 1. Parallel Branches Without the Pain # Review a PR without touching your current work git worktree add ../pr-review feature/new-dashboard cd ../pr-review git log --oneline -5 # Check the commits npm test # Run the tests cd ../project git worktree remove ../pr-review 2. Side-by-Side Comparison Want to compare your branch against main? Open them in two editor windows: git worktree add ../project-main main # Now open ../project/ (your branch) and ../project-main/ (main) side by side 3. CI Debugging Without Stopping Everything # Keep working on feature/x while debugging CI on a specific commit git worktree add ../ci-debug 7a3f9e1 cd ../ci-debug npm ci && npm test # ... debug CI failure without touching ../project/ 4. Documentation and README Updates The classic "quick fix while in the middle of something": git worktree add ../docs-update main cd ../docs-update # Edit README, commit, push cd ../project git worktree remove ../docs-update # Back to your feature branch, zero context loss The Workflow That Changed My Life Here's my daily workflow now: # Monday morning: start feature git checkout -b f