bashadvanced
Git Worktree for Multiple Branches
Work on multiple branches simultaneously using git worktree without stashing or switching.
bashPress ⌘/Ctrl + Shift + C to copy
# Add a worktree for a different branch
git worktree add ../project-hotfix hotfix/critical-fix
# Add a worktree and create a new branch
git worktree add -b feature/new-feature ../project-feature main
# List all worktrees
git worktree list
# Navigate to the worktree and work normally
cd ../project-hotfix
git status
npm install && npm run build
git add . && git commit -m "fix: resolve critical issue"
git push origin hotfix/critical-fix
# Go back to main worktree
cd ../project
# Remove a worktree when done
git worktree remove ../project-hotfix
# Prune stale worktree references
git worktree prune
# Lock a worktree to prevent accidental removal
git worktree lock ../project-feature
# Unlock a worktree
git worktree unlock ../project-featureUse Cases
- Reviewing PRs while working on a feature
- Hotfix deployment without disrupting current work
- Running tests on multiple branches in parallel
Tags
Related Snippets
Similar patterns you can reuse in the same workflow.
bashintermediate
Git Rebase Workflow Example
Step-by-step git rebase workflow to keep feature branches up to date with main branch cleanly.
Best for: Keeping feature branches linear with main
#git#rebase
bashintermediate
Git Cherry-Pick Commits Example
Apply specific commits from one branch to another using cherry-pick with conflict resolution.
Best for: Backporting bug fixes to release branches
#git#cherry-pick
bashbeginner
Git Aliases for Productivity
Essential git aliases and config settings to speed up daily git workflow and reduce typing.
Best for: Speeding up daily git workflow
#git#aliases
bashbeginner
Git Stash — Named, Partial, and Pop Strategies
Advanced stash techniques: named stashes, partial stash, stash apply vs pop, and branch from stash.
Best for: Saving work in progress before switching branches
#git#stash