Git & Version Controladvanced
Set up and manage git worktrees for parallel development
Git Worktree Setup
Set up and manage git worktrees for parallel development
Set up git worktrees for parallel development.
Instructions
- List existing worktrees:
git worktree list
- Create a worktree for a different branch:
# Work on a hotfix while keeping current branch open
git worktree add ../my-repo-hotfix hotfix/critical-bug
# Create a new branch in a worktree
git worktree add ../my-repo-feature -b feature/new-feature
- Work in the new directory:
cd ../my-repo-hotfix
# Make changes, commit, push — it's a separate working directory
# but shares the same .git repo
- Remove worktree when done:
cd ../my-repo # go back to main worktree
git worktree remove ../my-repo-hotfix
# or: rm -rf ../my-repo-hotfix && git worktree prune
When to Use Worktrees
- Reviewing a PR while working on something else
- Running long tests on one branch while coding on another
- Comparing behavior between branches side-by-side
- Hotfix while in the middle of a feature
Tips
- Each worktree can only have one branch checked out (no duplicates)
- npm install may be needed separately in each worktree