Recently while I mounted a HDD in my Linux workstation, I tried to download a new repo in the new disk so when I executed the command git submodule update –init –recursive, it showed me an unexpected error; ‘fatal: detected dubious ownership in repository at’. A snippet of the error is given below:
fatal: detected dubious ownership in repository at '/media/data/users/jhu3szh/serialize'
To add an exception for this directory, call:
git config --global --add safe.directory /media/data/users/jhu3szh/serialize
I would like to share the steps that helped me to fix the ‘fatal: detected dubious ownership in repository at’ error.
Why ‘fatal detected dubious ownership in repository at’ error seen?
The ‘fatal: detected dubious ownership in repository at’ error; is seen because you do not have the proper permissions in your project directory. You have to either ensure that all repositories are to be owned by the correct owner-ID or bypass the security completely.
To completely bypass the security, add *
as a “safe” directory.
A simple and optimal solution to this problem is to, try chown -R <current_user> <repo_folder> this will change the owner and for the directory.
A detailed solution to fix ‘fatal: detected dubious ownership in repository is mentioned below:
How to fix ‘fatal: detected dubious ownership in repository at’ error?
To fix the ‘fatal: detected dubious ownership in repository at’ error, Change the ownership of the directory. This will fix the error and “fatal: detected dubious ownership in repository at’ error will be resolved.
Alternatively disable the Safe Directory manually using the command git config –global –add safe.directory ‘* and it would disable directory config and change the directory setting as [safe] directory = *.
Below are the all possible methods to fix the fatal: detected dubious ownership in repository at’ error:
Method 1: Change Directory Ownership
You can change the ownership manually by following the command chown -R <current_user> <repo_folder>.
chown -R <current_user> <repo_folder>
Following the above mentioned step should fix the error fatal: detected dubious ownership in repository at’ error.
Method 2: Disable Safe Directory Manually
Alternatively to fix the fatal: detected dubious ownership in repository at’ error, disable the Safe Directory Manually, this would remove the all unsafe repository related errors for you immediately.
Disable the Safe Directory, using the command “git config –global –add safe.directory ‘*'”, :
git config --global --add safe.directory '*'
That would change the directory configuration as [safe] directory = * and this would solve the fatal: detected dubious ownership in repository at’ error.
[safe]
directory = *
if git config –global –add safe.directory ‘*’ command doesn’t work for you and throws error, try to use the command git config --global --add safe.directory "*"
into your terminal. so just changing the single quote with double quote in command git config –global –add safe.directory ‘*’ would help you to run the command without any error.
Note: before using the second method as a fix, you should understand the consequences as well of disabling the safe directory setting. you must avoid to disable the safe directory if your repositories are stored on a shared drive.
Disabling the Safe Directory Manually method can be used if repositories are stored locally on your pc and no unauthorised access can be taken.
Conclusion
To fix the ‘fatal: detected dubious ownership in repository at’ error, Change the ownership of the directory by running “chown -R <current_user> <repo_folder>” command. This will fix the error and “fatal: detected dubious ownership in repository at’ error and error will be resolved.
Alternatively, To fix the ‘fatal: detected dubious ownership in repository at’ error, disable the Safe Directory manually using the command git config –global –add safe.directory ‘*. This will fix the error and “fatal: detected dubious ownership in repository at’ error and error will be resolved.