fatal: detected dubious ownership in repository — how to fix
fatal: detected dubious ownership in repository at '/path/to/repo'
To add an exception for this directory, call:
git config --global --add safe.directory /path/to/repo
Quick fix: If you trust the repo, run git config --global --add safe.directory /path/to/repo. Better: fix ownership with sudo chown -R $(whoami) /path/to/repo.
What it means
Since Git 2.35.2, Git refuses to read a repository whose files belong to a different user than the one running Git. A malicious .git/config in a shared folder could otherwise make Git run commands as you.
Fix 1: take ownership (best when it's your project)
sudo chown -R "$(whoami)" /path/to/repo
Fix 2: mark the directory as safe
git config --global --add safe.directory /path/to/repo
To trust every directory (only on single-user machines or throwaway containers):
git config --global --add safe.directory '*'
Common situations
- Docker / CI containers. The checkout is owned by a different UID than the user inside the container. Add the
safe.directoryline in your Dockerfile or CI step, or run the container with--user "$(id -u):$(id -g)". - GitHub Actions in containers. Run
git config --global --add safe.directory "$GITHUB_WORKSPACE"before your git commands. - WSL with Windows drives (
/mnt/c/...) or external NTFS/exFAT drives. These file systems don't keep Linux owners. Usesafe.directory, or keep repos in your Linux home folder. - You used
sudo git ...once. Some files are now owned by root. Fix with thechowncommand above.
Last updated 2026-10-27.