GitWorktree.org logoGitWorktree.org

Git Worktree Workflow for Parallel Development

Traditional Git workflows force you to context-switch by stashing changes or committing half-finished work before jumping to another branch. Git worktree eliminates this friction by letting you keep multiple branches checked out simultaneously in separate directories.

The Parallel Development Problem

Imagine you are deep in a feature branch, with uncommitted changes spread across a dozen files. A critical bug report arrives and needs an immediate hotfix on main. Without worktrees your options are:

  • git stashyour work, switch branches, fix the bug, switch back, and pop the stash — hoping nothing conflicts.
  • Make a throwaway commit, switch branches, fix the bug, switch back, and soft-reset the commit.
  • Clone the repository a second time, doubling disk usage and losing your local configuration.

All three approaches are error-prone and slow. Worktrees solve this by giving each branch its own directory while sharing a single .git object store.

Setting Up a Worktree Workflow

Start from your existing clone and create worktrees as sibling directories. This keeps your file system clean and avoids nesting issues.

Creating worktrees
# You are in ~/projects/myapp (main branch)
# Create a worktree for a feature branch
git worktree add ../myapp-feature-auth feature/auth

# Create a worktree for a new branch (created automatically)
git worktree add -b feature/payments ../myapp-feature-payments

# List all worktrees
git worktree list

Each directory is a fully functional checkout. You can open them in separate editor windows, run tests independently, and switch between them by simply changing directories — no git checkout required.

Hotfix While Developing

This is the most common parallel development scenario. You are working on a feature and need to ship a hotfix without losing any context.

Hotfix without context-switching
# 1. You are in ~/projects/myapp-feature-auth, mid-feature
#    A critical bug is reported against main

# 2. Create a hotfix worktree (no stashing, no switching)
cd ~/projects/myapp
git worktree add ../myapp-hotfix-login hotfix/login

# 3. Fix the bug in the hotfix worktree
cd ../myapp-hotfix-login
# ... make changes, test ...
git add -A && git commit -m "fix: prevent login crash on expired token"

# 4. Push and merge the hotfix
git push origin hotfix/login

# 5. Go back to your feature — exactly where you left off
cd ../myapp-feature-auth
# Your editor state, uncommitted changes, everything is intact

PR Review Workflow

Reviewing pull requests locally is much easier with worktrees. Instead of stashing your work and checking out the PR branch, spin up a dedicated worktree.

Reviewing a pull request
# Fetch the PR branch
git fetch origin pull/42/head:pr-42

# Create a worktree for the review
git worktree add ../myapp-pr-42 pr-42

# Open it in your editor and run tests
cd ../myapp-pr-42
npm test

# When you're done reviewing, clean up
cd ../myapp
git worktree remove ../myapp-pr-42
git branch -D pr-42

This approach lets you review multiple PRs simultaneously, each in its own directory, while your own feature work remains untouched.

Multi-Feature Parallel Work

When you are juggling several features or experiments, worktrees let you keep all of them active at once. A typical layout might look like:

Multiple worktrees for parallel work
~/projects/
├── myapp/                      # main branch (stable reference)
├── myapp-feature-auth/         # authentication feature
├── myapp-feature-payments/     # payments integration
├── myapp-experiment-new-ui/    # UI experiment
└── myapp-bugfix-cart/          # cart bug fix

You can verify all your worktrees at any time:

Listing worktrees
$ git worktree list
/home/dev/projects/myapp                     abc1234 [main]
/home/dev/projects/myapp-feature-auth        def5678 [feature/auth]
/home/dev/projects/myapp-feature-payments    ghi9012 [feature/payments]
/home/dev/projects/myapp-experiment-new-ui   jkl3456 [experiment/new-ui]
/home/dev/projects/myapp-bugfix-cart         mno7890 [bugfix/cart]

Cleanup After Merging

Once a branch is merged, remove its worktree promptly. Stale worktrees waste disk space and make git worktree list noisy.

Cleaning up worktrees
# Remove a specific worktree
git worktree remove ../myapp-feature-auth

# If the directory was already deleted manually, prune metadata
git worktree prune

# Delete the merged branch
git branch -d feature/auth

# Tip: preview what prune would remove
git worktree prune --dry-run

For teams that create many short-lived worktrees, consider adding git worktree prune to a post-merge Git hook or a periodic cleanup script.

Related Guides