Today's game-changer: git worktree
(because context switching is expensive)
The Problem
You're deep in a feature branch, everything's messy, half-committed, and then:
"Hey, can you quickly check that bug in main?"
Your options:
- Stash everything, switch branches, lose your mental model
- Clone the repo again (and wait for node_modules to install... again)
- Commit incomplete work with "WIP: will fix later"
All terrible.
The Solution
Git worktrees let you check out multiple branches simultaneously in separate directories:
# Create a new worktree for hotfix git worktree add ../myproject-hotfix main # Now you have: # ~/myproject/ (your feature branch) # ~/myproject-hotfix/ (clean main branch)
The Workflow
# Working on feature-xyz cd ~/myproject # Bug report comes in git worktree add ../myproject-hotfix main cd ../myproject-hotfix # Fix bug, commit, push git checkout -b hotfix/urgent-fix # ... fix and commit git push origin hotfix/urgent-fix # Back to feature work cd ~/myproject # Your half-finished work is exactly as you left it
Why This Rules
- No context switching - your mental model stays intact
- No stashing - work in progress stays in progress
- Separate node_modules - no dependency conflicts
- Parallel development - review PRs while coding
Pro Tips
List all worktrees:
git worktree list
Clean up when done:
git worktree remove ../myproject-hotfix
Share .env files between worktrees:
# In your main project ln -s ../myproject/.env .env
My Setup
I keep a dedicated worktree for code reviews:
git worktree add ../myproject-review main
Now I can review PRs without losing my place. Game changer for focus.
How do you handle context switching? Still stashing like it's 2015, or do you have a better trick? Share your workflow below! 🔄
Tomorrow: What I Broke Wednesday (spoiler: involves leaking credentials)
Top comments (0)