Back to Flow

JJ Workspaces: Work on Multiple Branches Simultaneously

docs/jj-workspaces-for-parallel-work.md

0.1.33.3 KB
Original Source

JJ Workspaces: Work on Multiple Branches Simultaneously

When you need to reference or work with code from another branch without disrupting your current work, use jj workspaces. This creates a second working copy of the same repo at a different path, pointed at a different revision.

The Problem

You're on feature-a actively coding. You need to send another Claude session a prompt like "study the tracing code on pr/main-fdb3446" — but you can't check out that branch without losing your current working state.

Solution: jj workspace add

bash
cd ~/code/org/project
jj workspace add ../project-traces -r pr/main-fdb3446

Flow wrapper (recommended):

bash
cd ~/code/org/project
f jj workspace lane traces --base pr/main-fdb3446 --path ../project-traces

Now you have two working copies sharing the same repo:

PathBranchUse
~/code/org/projectfeature-aYour active work (untouched)
~/code/org/project-tracespr/main-fdb3446Full checkout for reference

Point any tool or Claude session at the second path — it has all files on disk, no risk to your branch.

Common Workflows

Reference code from another branch

bash
# Create workspace
jj workspace add ../project-ref -r some-branch

# Now another Claude session can freely explore:
# "study ~/code/org/project-ref — it has the tracing code"

# Clean up when done
jj workspace forget project-ref && rm -rf ../project-ref

Cherry-pick files across branches

bash
# No workspace needed — jj reads any revision directly:
jj file show src/lib/tracing.ts -r pr/main-fdb3446
jj diff --from main --to pr/main-fdb3446 --stat

Work on two PRs at once

bash
f jj workspace lane pr2 --base pr/feature-b --path ../project-pr2
# Edit files in both directories independently
# Both share the same jj repo — commits are visible everywhere

Reuse one stable workspace for a review branch

bash
f jj workspace review review/alice-feature
cd ~/.jj/workspaces/project/review-alice-feature

Use this when you want one predictable workspace path for a specific review branch instead of a general-purpose lane.

Default isolated lanes from trunk

bash
f jj workspace lane fix-otp
f jj workspace lane release-testflight

By default this fetches and anchors each lane on <default_branch>@<remote> (or <default_branch> if the remote bookmark is missing).

How It Works

  • Both workspaces share the same .jj/ repo backend (no git clone, no duplication)
  • Each workspace has its own working copy commit (@)
  • Changes committed in one workspace are immediately visible in the other via jj log
  • The original workspace is completely unaffected

Cleanup

bash
# List workspaces
jj workspace list

# Remove a workspace (keeps the commits, removes the directory association)
jj workspace forget <name>
rm -rf ../project-ref

When to Use What

NeedTool
Full directory for another tool/session to explorejj workspace add
Stable branch-specific review workspacef jj workspace review <branch>
Read a specific file from another branchjj file show <path> -r <rev>
See what changed on another branchjj diff --from main --to <branch>
Compare two branchesjj log -r 'branchA..branchB'