Git Worktrees: Work on Multiple Branches Simultaneously
Use git worktrees to check out multiple branches in separate directories without stashing or committing, enabling true parallel development.
Tags
Git Worktrees: Work on Multiple Branches Simultaneously
TL;DR
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.
The Problem
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.
The Solution
# 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 mainCommon Commands Cheatsheet
git 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 referencesWhy This Works
All 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
Need help with a project?
Let's Build It
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.
Related Articles
TypeScript Utility Types You Should Know
Five essential built-in generic utility types in TypeScript that will save you hundreds of lines of code.
Generate Dynamic OG Images in Next.js
Generate dynamic Open Graph images in Next.js using the ImageResponse API with custom fonts, gradients, and data-driven content for social sharing.
GitHub Actions Reusable Workflows: Stop Repeating Yourself
Create reusable GitHub Actions workflows with inputs, secrets, and outputs to eliminate YAML duplication across repositories and teams efficiently.