Skip to content
fatal: detected dubious ownership in repository

fatal: detected dubious ownership in repository

DodaTech 3 min read

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 by root).
  • 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/repo

This tells Git to trust that specific directory. Verify it was added:

git config --global --get-all safe.directory

2. 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/repo

After 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 --list

You can add to the system config with:

git config --system --add safe.directory /path/to/repo

(Requires appropriate permissions.)

Why did Git add this safety check?
CVE-2022-24765 described a vulnerability where a shared repository owned by one user could execute Git commands as another user, leading to arbitrary code execution. Git’s safe.directory mechanism prevents this by requiring explicit trust for cross-owner repositories. It was backported to all maintained Git versions in early 2022.
Is it safe to use '*' for safe.directory?
On a personal, single-user machine, using * is generally safe. On a multi-user system or server, never use * — it disables the security check entirely. Instead, add specific directories with git config --global --add safe.directory /path/to/repo.
Does this affect Git GUI clients?
Yes — Git GUI tools like GitHub Desktop, GitKraken, and VS Code’s Git integration also use the system Git binary and will show the same error. The fix is identical: either mark the directory as safe or fix the ownership. After fixing, restart the GUI tool to clear the error.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro