Switching branches loses unsaved work. Worktree creates separate folder for each branch.
Create Worktree:
# Create worktree for feature branch git worktree add ../myproject-feature feature-branch # Now you have: # ~/myproject/ (main branch) # ~/myproject-feature/ (feature branch)
Work in Both:
Open both folders in separate VS Code windows – work on both branches at once!
List Worktrees:
git worktree list
Remove Worktree:
git worktree remove ../myproject-feature
Use Case: Hotfix on main while developing feature – no branch switching needed!
