How to Fix Git’s “dubious ownership” Error
fatal: detected dubious ownership in repository is the error you get when you run git status or git log in a repository owned by a different user. It happens with folders cloned by another user or by root, and with folders shared with other people. Run the command the error suggests, git config --global --add safe.directory <repository path>, or change the folder's owner to yourself, and the same command will work. I reproduced the error in a test environment and include the output after the fix as it appeared.
The test environment was Ubuntu 24.04 with Git 2.43.0. The user names are examples: the repository is owned by tama, and git is run as neko. The repository path /srv/shared/app was also created just for this test. I started each test with an empty home folder and without reading the system-wide Git config. I did not test Windows or macOS, Git for Windows, running git with sudo, or the behavior when safe.directory is written to the system-wide config (git config --system).
The full error and when it appears
The repository /srv/shared/app is owned by tama, both the folder and the .git inside it.
$ whoami
neko
$ ls -ld /srv/shared/app /srv/shared/app/.git | cut -d" " -f1,3,4,9
drwxrwxr-x tama tama /srv/shared/app
drwxrwxr-x tama tama /srv/shared/app/.git
The permissions are rwxrwxr-x, so neko can read the folder. Even so, running git status in this repository as neko stopped with the following error.
$ git status; echo "exit=$?"
fatal: detected dubious ownership in repository at '/srv/shared/app'
To add an exception for this directory, call:
git config --global --add safe.directory /srv/shared/app
exit=128
The first line means that the repository at /srv/shared/app looks dubious because of its ownership. The rest of the message says "To add an exception for this directory, call:" and gives the command to run, with the path already filled in.
git log gave the same error. Running it inside the src folder of the repository also failed, but the path in the error is not src. It is /srv/shared/app, the top-level folder of the repository.
$ pwd
/srv/shared/app/src
$ git status; echo "exit=$?"
fatal: detected dubious ownership in repository at '/srv/shared/app'
To add an exception for this directory, call:
git config --global --add safe.directory /srv/shared/app
exit=128
This check was added as a countermeasure against the vulnerability CVE-2022-24765. The Git 2.36 release notes say that Git was changed so it no longer recognizes repositories owned by other users, so that their config files and hooks cannot affect you. As the safe.directory documentation explains, by default Git does not read the config of a repository you do not own, and does not run its hooks.
Fix it by registering the repository in safe.directory
Run the command from the error message as neko.
$ git config --global --add safe.directory /srv/shared/app
$ cat ~/.gitconfig
[safe]
directory = /srv/shared/app
Because I used --global, the entry was written to ~/.gitconfig in neko's home folder. After I ran git status and git log again, the error no longer appeared.
$ git status; echo "exit=$?"
On branch main
nothing to commit, working tree clean
exit=0
$ git log --oneline; echo "exit=$?"
5e4e768 最初のコミット
exit=0
git status --short run inside the src folder also succeeded with exit code 0. Registering the top-level folder works for commands run from its subfolders too.
You can add as many safe.directory entries as you need with --add. If you have several repositories, add the path of each one.
Removing the entry
To delete the registered values, use git config --global --unset-all safe.directory. After that, the same error appeared again.
$ git config --global --unset-all safe.directory; echo "exit=$?"
exit=0
$ git config --global --get-all safe.directory; echo "exit=$?"
exit=1
$ git status; echo "exit=$?"
fatal: detected dubious ownership in repository at '/srv/shared/app'
To add an exception for this directory, call:
git config --global --add safe.directory /srv/shared/app
exit=128
Settings that do not stop the error
safe.directory has no effect if you write it in the wrong place or use the wrong path. In my test environment, these three cases did not clear the error.

The first is writing it to .git/config inside the repository. Even when the owner tama wrote it with git config --local, neko still got the same error.
$ cat .git/config
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
[safe]
directory = /srv/shared/app
$ git status; echo "exit=$?"
fatal: detected dubious ownership in repository at '/srv/shared/app'
To add an exception for this directory, call:
git config --global --add safe.directory /srv/shared/app
exit=128
According to the git config documentation, safe.directory is read only from the system-wide config (--system), the user config (--global), and config passed on the command line (git -c). If a repository's own config could declare itself safe, the check would be pointless.
The second is registering the path of a subfolder where the error appeared. Even if you work in src, register the top-level folder shown in at '…' in the error.
$ git config --global --add safe.directory /srv/shared/app/src
$ git config --global --get-all safe.directory
/srv/shared/app/src
$ git status; echo "exit=$?"
fatal: detected dubious ownership in repository at '/srv/shared/app'
To add an exception for this directory, call:
git config --global --add safe.directory /srv/shared/app
exit=128
The third is adding a trailing / to the path. In Git 2.43.0, registering /srv/shared/app/ is treated as a different path from /srv/shared/app, and the error did not go away.
$ git config --global --add safe.directory /srv/shared/app/
$ git status; echo "exit=$?"
fatal: detected dubious ownership in repository at '/srv/shared/app'
To add an exception for this directory, call:
git config --global --add safe.directory /srv/shared/app
exit=128
You can avoid all three by copying the command shown on the last line of the error exactly.
To run it once, use git -c
If you do not want to leave an entry in a config file, you can allow a single command with git -c safe.directory=<path>. The following command ran successfully, and the next plain git status still failed with the same error.
$ git -c safe.directory=/srv/shared/app log --oneline; echo "exit=$?"
5e4e768 最初のコミット
exit=0
$ git status; echo "exit=$?"
fatal: detected dubious ownership in repository at '/srv/shared/app'
To add an exception for this directory, call:
git config --global --add safe.directory /srv/shared/app
exit=128
If it is your repository, change the owner to yourself
If the repository should really be yours, for example because you cloned it as root or as another user, you can skip safe.directory and change the owner to yourself. I ran chown -R as root to change the owner to neko. No safe.directory entry was set.
$ chown -R neko:neko /srv/shared/app
$ ls -ld /srv/shared/app /srv/shared/app/.git | cut -d" " -f1,3,4,9
drwxrwxr-x neko neko /srv/shared/app
drwxrwxr-x neko neko /srv/shared/app/.git
$ git config --global --get-all safe.directory; echo "exit=$?"
exit=1
$ git status; echo "exit=$?"
On branch main
nothing to commit, working tree clean
exit=0
Once you own the repository, the check no longer applies. Keep in mind, though, that by default Git only works with repositories owned by the user running it. If you change the owner of a shared repository that other users also use, those users will hit this check instead. The safe.directory documentation lists the intended use of this setting as repositories that you deliberately share.
Putting * in safe.directory turns the check off
If you put * in safe.directory, every repository is treated as registered. In my test environment, git log also ran without error in a different repository, /srv/shared/other, which I had not registered.
$ git config --global --add safe.directory '*'
$ cat ~/.gitconfig
[safe]
directory = *
$ pwd
/srv/shared/other
$ git log --oneline; echo "exit=$?"
5e4e768 最初のコミット
exit=0
As the safe.directory section of the official documentation says, * turns off this security check completely. Hooks and config from repositories owned by other users will then be used just like your own. Do not add * just to clear the error. Register the paths of trusted repositories one at a time instead.


