Guides
Two worktrees, two Linux sessions
Use one terminal to check out two branches, build in one Linux guest, and verify that the other guest has its own state.
Start inside a local Git repository with at least one commit. You’ll need Git, tar and the unContainer CLI on a supported host. Pick unused branch names and sibling directories for this exercise.
1. Create the worktrees on the host
Git creates each directory and checks out a new branch at the current commit. Your original checkout stays where it is. Uncommitted edits in it stay there too. Keep this terminal open so the path variables remain available.
repo=$(git rev-parse --show-toplevel)
api="$repo/../uc-demo-api"
review="$repo/../uc-demo-review"
git -C "$repo" worktree add -b uc-demo/api "$api" HEAD
git -C "$repo" worktree add -b uc-demo/review "$review" HEAD
git -C "$repo" worktree listYou should see your original checkout plus entries for uc-demo/api and uc-demo/review.
2. Work inside the first guest
Change directories on the host to select the API worktree. Opening the session copies that checkout into /work. The shell after session exec -- runs inside Linux.
cd "$api"
uncontainer session open --publish 3000
uncontainer session exec -- pwd
uncontainer session exec -- ls -aExpect /work and your project files. Make a small stand-in for a build artifact, then read it in a separate invocation. You should see API build ready.
uncontainer session exec -- sh -c 'echo "API build ready" > /tmp/uc-demo-artifact'
uncontainer session exec -- cat /tmp/uc-demo-artifact3. Switch branches by switching directories
Open the review guest and check for the artifact. Both guests can publish port 3000 because each gets its own loopback port on the host.
cd "$review"
uncontainer session open --publish 3000
uncontainer session exec -- sh -c 'test ! -e /tmp/uc-demo-artifact && echo "Separate guest"'
uncontainer session list --jsonExpect Separate guest. Find each worktree’s path in the session list and compare its forwards entries. If you start your project’s server on guest port 3000, reach that specific branch at 127.0.0.1 using its assigned host port.
4. Return to the first session
cd "$api"
uncontainer session open
uncontainer session exec -- cat /tmp/uc-demo-artifactYou should see API build ready again. For real work, edit source in the host worktree. Use uncontainer run -- … to check a fresh copy, or close and reopen the session to pick up later host edits. Save any needed guest output before closing.
5. Close the sessions and remove the checkouts
When you’re done with both guests, close each one from its worktree. Return to the original checkout before asking Git to remove the two directories.
cd "$api"
uncontainer session close
cd "$review"
uncontainer session close
cd "$repo"
git worktree remove "$api"
git worktree remove "$review"
git worktree listThe two branch names remain available in Git. If Git reports local changes during removal, inspect and save the work you want to keep.