Loading…
Loading…
Use git worktrees to check out multiple branches in separate directories without stashing or committing, enabling true parallel development.
Tags
Use git worktree add to check out multiple branches in separate directories so you can work on a hotfix and a feature simultaneously without stashing or committing.
You are mid-feature on a branch when a critical bug report arrives. You either stash your work (and risk losing context), make a messy WIP commit, or clone the repo again. All three options are clunky and slow.
# Create a worktree for the hotfix branch
git worktree add ../hotfix-login hotfix/login-bug
# Now you have two directories:
# /projects/my-app → feature/new-dashboard (your current work)
# /projects/hotfix-login → hotfix/login-bug (new worktree)
# Work on the hotfix in the new directory
cd ../hotfix-login
# fix the bug, commit, push...
# List all active worktrees
git worktree list
# /projects/my-app abc1234 [feature/new-dashboard]
# /projects/hotfix-login def5678 [hotfix/login-bug]
# Remove the worktree when done
git worktree remove ../hotfix-loginYou can also create a worktree with a new branch in one command:
# Create a new branch AND worktree simultaneously
git worktree add -b feature/quick-fix ../quick-fix maingit worktree add <path> <branch> # Create worktree for existing branch
git worktree add -b <branch> <path> # Create worktree with new branch
git worktree list # Show all worktrees
git worktree remove <path> # Remove a worktree
git worktree prune # Clean up stale worktree referencesAll worktrees share the same .git repository data, so commits, branches, stash, and remotes are consistent across all linked directories. Each worktree has its own working directory and index, so you can stage, edit, and run builds independently. Unlike cloning the repo, worktrees use no extra disk space for git objects and stay perfectly in sync. The only constraint is that each branch can only be checked out in one worktree at a time.
Collaboration
I help startups and established companies design, build, and scale world-class digital products. From deep technical architecture to pixel-perfect UI: let's bring your vision to life.
Five essential built-in generic utility types in TypeScript that will save you hundreds of lines of code.
Generate dynamic Open Graph images in Next.js using the ImageResponse API with custom fonts, gradients, and data-driven content for social sharing.
Create reusable GitHub Actions workflows with inputs, secrets, and outputs to eliminate YAML duplication across repositories and teams efficiently.