fatal: detected dubious ownership in repository
Git’s fatal: detected dubious ownership in repository error is a security check that prevents you from running Git commands in a repository owned by a different user than the current one.
What It Means
Starting with Git 2.35.2 (February 2022), Git introduced a safety feature called safe.directory. When you run a Git command in a directory where the .git folder is owned by a different user (e.g., root), Git refuses to proceed. This mitigates a vulnerability (CVE-2022-24765) where a malicious actor could create a .gitconfig in a shared directory to execute arbitrary commands.
The full error looks like:
fatal: detected dubious ownership in repository at '/path/to/repo'
'/path/to/repo' is owned by:
'root' (or another user)
but the current user is:
'your-username'Why It Happens
- You cloned a repo with
sudo git clone(the.git/folder is owned byroot). - You’re working in a directory owned by another user (e.g.,
/var/www/deployed by a root process). - You restored a project from a backup that preserved the original ownership.
- A container or VM mapped a volume with mismatched UIDs.
- A teammate created the project using a different system user.
How to Fix It
1. Add the directory to Git’s safe list (recommended)
git config --global --add safe.directory /path/to/repoThis tells Git to trust that specific directory. Verify it was added:
git config --global --get-all safe.directory2. Add the current directory wildcard (convenient but less secure)
git config --global --add safe.directory '*'This trusts all directories on your system. Use this only on personal machines where you understand the security implications.
3. Fix the ownership with chown (permanent fix)
Change the repository ownership to your user:
sudo chown -R $(whoami):$(whoami) /path/to/repoAfter this, Git commands will work without any config changes.
4. Check system-level Git config
If the global config doesn’t work, check the system-level config:
git config --system --listYou can add to the system config with:
git config --system --add safe.directory /path/to/repo(Requires appropriate permissions.)
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro