fatal: detected dubious ownership in repository at ‘…’ git – Code Example

Total
0
Shares

In this article I will show you the solution to the git error – fatal: detected dubious ownership in repository at ‘…’. This error shows that there are issues with ownership of the repository. It occurs due to wrong permissions on directory structure where repository is cloned.

When does this error occur?

Suppose you are cloning a repository in some folder where user permissions are not proper, and you run this command –

git clone REPO

Everything seems alright and when you try to cd the folder you might get this –

fatal: detected dubious ownership in repository at '/var/projects/myrepo'
To add an exception for this directory, call:

git config --global --add safe.directory /var/projects/myrepo

If you try to add this directory to safe.directory using this command –

git config --global --add safe.directory /var/projects/myrepo

More issues might pop up. This is due to wrong permissions on the parent directory.

Solution

1. Change the owner of the project

chown -R <current_user> <repo_folder>

2. Suppress safe.directory warnings

You may also suppress the warnings but this is not recommended. You should know that it could lead to security issues.

git config --global --add safe.directory '*'

3. Check if you are on the correct user in terminal

Sometimes we need to switch users like going to root. Check if you are logged in as appropriate user. If not then change it –

su correct_user