devcontainer: add optional worktrees mount#3541
Merged
Conversation
Add an optional `DZ_WORKTREES_DIR` mount that exposes a host worktrees directory at /workspaces/worktrees inside the container. Useful when using `docker exec` to run builds in the persistent dev container while working on git worktrees outside the repo checkout. Defaults to /tmp/worktrees (created by initializeCommand) when the env var is unset, so the mount is a harmless no-op for devs who don't use it.
snormore
approved these changes
Apr 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
DZ_WORKTREES_DIRhost env var that mounts a worktrees directory at/workspaces/worktreesinside the dev container, sodocker execworkflows can reach git worktrees stored outside the main repo checkout/tmp/worktrees(created byinitializeCommand) when the env var is unset — harmless empty mount for devs who don't opt inresolveShellEnvpicks up the env var from shell rcMotivation
The persistent dev container (
dz-dev-workspace-vsc) is used viadocker execfor Linux builds. Worktrees kept in a global location (e.g.~/projects/worktrees/) are not visible inside the container without a mount, so switching between worktrees required constant rebuilds or host-side tooling.Opt-in
Add one line to your shell rc:
Then rebuild the dev container. Your worktrees appear at
/workspaces/worktrees/inside the container, mirroring the host layout.Testing Verification
DZ_WORKTREES_DIRset; confirmed mount source resolves to$HOME/projects/worktreesviadocker inspect/workspaces/worktrees/shows host worktrees content/tmp/worktrees, created byinitializeCommandresolveShellEnv