Blog/Quick Tips & Snippets/Git Worktrees: Work on Multiple Branches Simultaneously
POST
August 05, 2025
LAST UPDATEDAugust 05, 2025

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

GitWorkflowDevOpsTips
Git Worktrees: Work on Multiple Branches Simultaneously
1 min read

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

bash
# 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-login

You can also create a worktree with a new branch in one command:

bash
# Create a new branch AND worktree simultaneously
git worktree add -b feature/quick-fix ../quick-fix main

Common Commands Cheatsheet

bash
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 references

Why 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.

SH

Article Author

Sadam Hussain

Senior Full Stack Developer

Senior Full Stack Developer with over 7 years of experience building React, Next.js, Node.js, TypeScript, and AI-powered web platforms.

Related Articles

TypeScript Utility Types You Should Know
Feb 10, 20263 min read
TypeScript
Cheatsheet

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
Feb 08, 20262 min read
Next.js
OG Images
SEO

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
Jan 22, 20263 min read
GitHub Actions
CI/CD
DevOps

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.