fatal: detected dubious ownership in repository
This error means the repository folder belongs to a different user than the one running Git. It is a security feature added in Git 2.35.2, not a corruption. One command fixes it.
What this error means
Since version 2.35.2, Git checks that the repository folder is owned by the user running the command. If it is owned by someone else (root, www-data, another account), Git stops immediately. This protects you from a real attack: a malicious .git folder planted in a shared directory could execute code on your machine through hooks or config settings.
Why this happens
Docker volumes and containers
Files mounted into a container often belong to root or to the host user's UID, while the container runs Git as a different user. Git sees a mismatch and refuses.
WSL and network drives
Repositories on a Windows drive accessed from WSL (under /mnt/c), or on NTFS/network shares, can report an owner that does not match your Linux user.
Servers, CI, and sudo
On a server, a deploy user owns the code but you connect as someone else. In CI, the checkout user differs from the build user. Running Git with sudo once can also flip ownership of some files.
How to fix it
Two clean options: declare the folder safe, or make yourself its owner.
Option 1: mark the folder as safe
If you trust the repository, copy the exact command Git suggests in the error message. It only affects that one path.
Option 2: fix the ownership
When you should genuinely own the files, change the owner instead. For containers and CI, a wildcard entry is common because the environment is controlled.
How to prevent it
Avoid sudo with Git
Running sudo git ... creates root-owned files inside your repository and causes this error later. Clone and work as your normal user.
Match UIDs in containers
In Docker, run the container with your host UID (--user $(id -u):$(id -g)) or bake a safe.directory entry into the image so builds do not break.
Scope exceptions narrowly
Prefer one safe.directory entry per path over the "*" wildcard, especially on shared machines. The protection exists for a reason.
GitQuest is created by Anaïs (nouvelle fenêtre), web developer and head of education, specializing in tech training and digital accessibility.
Questions about dubious ownership
Git errors become clues, not roadblocks
GitQuest teaches you to read what Git is really saying. Practice in a safe terminal simulator and turn every error message into a solved case.
Start practicing