Support launching the devcontainer from a git worktree#8950
Open
alliepiper wants to merge 2 commits into
Open
Conversation
In a linked git worktree, `.git` is a file pointing to
<main-repo>/.git/worktrees/<name> via an absolute host path. The
container only mounts the worktree at /home/coder/cccl, so the gitdir
pointer (and the main .git it links back to via commondir) is
unreachable, and every git operation in the container fails. Bind-mount
the main repo's .git directory at its absolute host path inside the
container so both the absolute gitdir pointer and the relative commondir
resolve.
The devcontainer also bind-mounts ${localWorkspaceFolder}/.config to
/home/coder/.config, which in a fresh worktree has no gh/ subdir, so
devcontainer-utils-init-git triggers an interactive `gh auth login`
device flow on startup. When the main checkout has a populated
.config/gh, share it into the worktree container so init-git skips the
device flow. Otherwise warn that the user must launch the main
checkout's devcontainer first to populate auth state.
Also warn that `cccl-build` and `cccl-wheelhouse` docker volumes are
shared across all worktrees and the main checkout — preexisting issue,
but worth surfacing when the worktree case lights up.
Contributor
Author
|
"the devcontainer" I'm a human I swear. |
This comment has been minimized.
This comment has been minimized.
bernhardmgruber
approved these changes
May 13, 2026
📝 WalkthroughSummary by CodeRabbit
WalkthroughThe devcontainer launch script now detects when running from a Git worktree, computes the shared Git directory, and bind-mounts it into the container. It also conditionally mounts shared auth config and emits warnings about shared Docker volumes. ChangesDevcontainer Git Worktree Integration
Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. Comment |
Contributor
😬 CI Workflow Results🟥 Finished in 2h 49m: Pass: 99%/500 | Total: 18d 17h | Max: 2h 48m | Hits: 23%/2836811See results here. |
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
Make
.devcontainer/launch.shwork when invoked from a linked git worktree.Two reasons it currently breaks:
.gitis unreachable inside the container. In a worktree,.gitisa file containing
gitdir: <main-repo>/.git/worktrees/<name>— anabsolute host path. The container only mounts the worktree at
/home/coder/cccl, so the gitdir pointer (and the main.gititreferences via
commondir) is unreachable. Every git operation inthe container fails.
ghauth state is missing. The devcontainer bind-mounts${localWorkspaceFolder}/.config → /home/coder/.config. In a freshworktree,
.config/gh/doesn't exist, sodevcontainer-utils-init-gitfalls through to an interactivegh auth logindevice flow on every startup.Changes
.devcontainer/launch.shlaunch_docker()now detects the worktreecase (
[[ -f .git ]]) and:.gitdirectory at its absolute host pathinside the container, so both the absolute
gitdir:pointer and therelative
commondirresolve..config/gh(when present) into/home/coder/.config/gh, sogh auth statuspasses anddevcontainer-utils-init-gitskips the device flow.cccl-buildandcccl-wheelhousedocker volumes are shared across all worktrees and the main
checkout (preexisting issue, but worth surfacing).
.config/gh/to share, additionallywarns that init-git will block on
gh auth loginand recommendslaunching the main checkout's devcontainer first to populate auth
state.
No-op when
.gitis a directory (regular checkout).Test plan
shellcheck,codespell, etc.) passes on.devcontainer/launch.sh..devcontainer/launch.sh -d -- bash -c '<git probes>'from the worktree completes without hanging on
gh auth login.Inside the container:
-
gh auth status→ ✓ Logged in asalliepiper-
git status→On branch devcontainer-worktree-fix(no"dubious ownership" error)
-
git rev-parse --git-dir→/home/allie/code/src/cccl/.git/worktrees/devcontainer-worktree-fix-
git rev-parse --git-common-dir→/home/allie/code/src/cccl/.git-
git logresolves commits correctly.