bashadvanced
Git Worktree — Work on Multiple Branches
Use git worktree to check out multiple branches simultaneously in separate directories.
bashPress ⌘/Ctrl + Shift + C to copy
# Add a worktree for a branch
git worktree add ../project-hotfix hotfix/critical-bug
# Creates ../project-hotfix/ with hotfix branch checked out
# Add worktree with a new branch
git worktree add -b feature/new-ui ../project-new-ui main
# List all worktrees
git worktree list
# /home/user/project abc1234 [main]
# /home/user/project-hotfix def5678 [hotfix/critical-bug]
# /home/user/project-new-ui ghi9012 [feature/new-ui]
# Work in the worktree (separate directory, shared .git)
cd ../project-hotfix
git log --oneline -5
# make changes, commit as usual
git add . && git commit -m "fix: critical auth bug"
# Remove a worktree when done
cd ../project
git worktree remove ../project-hotfix
# Force remove (if there are changes)
git worktree remove --force ../project-hotfix
# Prune stale worktree references
git worktree prune
# Lock a worktree (prevent accidental removal)
git worktree lock ../project-new-uiUse Cases
- Reviewing PRs without stashing current work
- Running tests on one branch while coding on another
- Hotfix deployment without disrupting feature work
Tags
Related Snippets
Similar patterns you can reuse in the same workflow.
bashadvanced
Git Worktree for Multiple Branches
Work on multiple branches simultaneously using git worktree without stashing or switching.
Best for: Reviewing PRs while working on a feature
#git#worktree
bashintermediate
Git Cherry-Pick — Apply Specific Commits
Cherry-pick single, multiple, or ranges of commits from other branches without full merge.
Best for: Backporting hotfixes to release branches
#git#cherry-pick
bashbeginner
Git Remote Prune and Branch Cleanup
Clean up stale remote-tracking branches and local branches that have been merged or deleted upstream.
Best for: Keeping local repository tidy
#git#cleanup
bashintermediate
Git Hooks Pre Commit
Git workflow: git-hooks-pre-commit
Best for: version control
#git#version-control