Skip to content

claude-code template: VS Code's Git extension intermittently hits "dubious ownership" on /workspace, and SSH GitHub remotes can't use the container's gh login #172

Closed

Description

@gatezh

Problem

1. "dubious ownership" on the bind-mounted workspace. In containers built from the claude-code template on Docker Desktop for Mac, VS Code's Git log (~/.vscode-server/data/logs/*/exthost*/vscode.git/Git.log) repeatedly shows:

fatal: detected dubious ownership in repository at '/workspace'
[GitHistoryProvider] ... "gitErrorCode": "NotASafeGitRepository"
  • It isn't limited to startup. In one container it recurred over several hours, and running git status by hand at the same moments usually succeeds.
  • Once the Git extension hits it, Source Control goes blank or stale until the window is reloaded.
  • A safe.directory entry written into ~/.gitconfig doesn't reliably help, because that file is managed or copied by the Dev Containers extension.

2. SSH-style GitHub remotes don't work inside the container. The template persists the GitHub CLI login in a volume (~/.config/gh), but gh only authenticates HTTPS. Repos whose remotes are [email protected]:… fail inside the container with Permission denied (publickey). The Dev Containers extension forwards only the host's default ssh-agent, and that often has no keys when the host uses another agent (Secretive, 1Password) or on-disk keys.

Proposal

Set git options for every process in the container through env-based config. It outranks ~/.gitconfig, doesn't touch the host, and needs no extra files. Add this to containerEnv in both devcontainer.json variants:

"GIT_CONFIG_COUNT": "3",
"GIT_CONFIG_KEY_0": "safe.directory",
"GIT_CONFIG_VALUE_0": "/workspace",
"GIT_CONFIG_KEY_1": "url.https://github.com/.insteadOf",
"GIT_CONFIG_VALUE_1": "[email protected]:",
"GIT_CONFIG_KEY_2": "credential.https://github.com.helper",
"GIT_CONFIG_VALUE_2": "!gh auth git-credential",
  • safe.directory=/workspace removes the ownership check for the one bind-mounted repo.
  • The insteadOf rewrite and the gh credential helper let SSH-style remotes work inside the container, using the persisted gh auth login. The host keeps its SSH setup, and the remotes themselves don't change.

This was checked in a running container by passing the same variables to a single command:

  • git config --get-all safe.directory printed /workspace.
  • git ls-remote --get-url [email protected]:<owner>/<private-repo>.git printed the https://github.com/… URL.
  • git ls-remote against the private repo listed its refs, authenticated through gh.

Acceptance

  • No dubious ownership or NotASafeGitRepository entries in the Git extension log after a rebuild.
  • Fetch, pull and push from VS Code and the terminal work in the container for [email protected]: remotes after one gh auth login.
  • The README documents both settings and the one-time gh auth login.

Activity

  1. added
    bug
    on Sep 24, 2026
  2. Repository owner deleted a comment from shadialhasan on Oct 1, 2026
  3. gatezh commented on Oct 7, 2026

    @gatezh
    OwnerAuthor

    The 3-entry version isn't enough on its own. VS Code injects its own credential helper into /etc/gitconfig and ~/.gitconfig. Git tries it first, and it answers with the host's GitHub credential, which may be stale. git push then fails with "Invalid username or token" even though gh is signed in.

    The fix is an empty credential.https://github.com.helper entry before the gh one. It resets the helper list for github.com only, so other hosts keep VS Code's helper:

    "GIT_CONFIG_COUNT": "4",
    "GIT_CONFIG_KEY_0": "safe.directory",
    "GIT_CONFIG_VALUE_0": "/workspace",
    "GIT_CONFIG_KEY_1": "url.https://github.com/.insteadOf",
    "GIT_CONFIG_VALUE_1": "[email protected]:",
    "GIT_CONFIG_KEY_2": "credential.https://github.com.helper",
    "GIT_CONFIG_VALUE_2": "",
    "GIT_CONFIG_KEY_3": "credential.https://github.com.helper",
    "GIT_CONFIG_VALUE_3": "!gh auth git-credential",

    Inside a container, git config --get-regexp credential shows the VS Code helper (a vscode-remote-containers-*.js git-credential-helper function) next to these entries. Pushes go through gh only when the empty entry is present.

    Verified in a downstream project built from this template: with three entries pushes fail as above, with the fourth they go through gh.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions