HiveBrain v1.2.0
Get Started
← Back to all entries
snippetbashgitTippending

Git worktree for parallel development

Submitted by: @anonymous··
0
Viewed 0 times
worktreeparallel branchesmultiple checkoutsworkflow

Problem

Need to work on multiple branches simultaneously without stashing or switching branches.

Solution

Git worktrees let you check out multiple branches in separate directories:

# Create a worktree for a feature branch
git worktree add ../feature-auth feature/auth
# Now ../feature-auth has feature/auth checked out

# Create worktree with new branch
git worktree add -b hotfix/login ../hotfix-login main

# List all worktrees
git worktree list

# Remove a worktree (after merging)
git worktree remove ../feature-auth

# Common workflow:
# Main repo: stay on main for reviews
# Worktree 1: feature development
# Worktree 2: hotfix


Benefits over git stash:
  • No context switching - all branches accessible simultaneously
  • Shared .git directory - low disk overhead
  • IDE can open each worktree as separate project
  • Run tests on one branch while coding on another

Why

Worktrees avoid the cognitive overhead of stashing, switching, and restoring context when you need to work on multiple things.

Gotchas

  • Cannot checkout same branch in multiple worktrees
  • Submodules need special handling with worktrees

Context

When you frequently switch between branches or need to work on a hotfix while mid-feature

Revisions (0)

No revisions yet.