Solved – Fatal: detected dubious ownership in repository

Fatal: detected dubious ownership in repository

When working with GitHub, you may encounter fatal: detected dubious ownership in repository. GitHub is an open platform to add the projects you designed, then the whole team of your can access that remotely as well. But when the error ownership in the repository occurs, you may be wondered how to remove the warning.

In this article, we are going to discuss how to fix the ‘Fatal: detected dubious ownership in repository’ error.

How the Error Occurs

This error occurs when you attempt to plug the drive into a Linux workstation and try to get a new repository on the new disk. For this, you use the command: git submodule replace –init –recursive, you may encounter the error.

Let’s have a look at how the error occurs

fatal: detected dubious ownership in repository at '/project'
To add an exception for this directory, call:
git config --global --add safe.directory /project

and simply

fatal: detected dubious ownership in repository

It is important to have permission in the challenging list to avoid the error. You need to ensure the repositories have certain that belong to the right proprietor ID.

How to Fix fatal: detected dubious ownership in repository

We have a few best solutions that can help you fix the error. Let’s have a look at the solutions

Solution 1 – Add safe Directory

This solution is one of the easiest ways to remove fatal error in the repository. To remove the unsafe repository, that can cause the error, disable checks. You need to follow the command to disable

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

with this command, you can have the. gitconfig line added in your file. It changes the directory configuration as a safe directory.

[safe]
    directory = *

with this, you can get the error solved.

You need to know that before taking a decision to use this method to fix the error, you also learn the consequences of disabling or manipulating the safe directory setting. In the case, you have the git repository stored on a shared drive, you should avoid this fix.  

Manual disabling the safe directory is used if your repository is stored on your pc locally with no unauthorized access taken.

Solution 2 – Change Ownership of Directory

You can manually change the ownership with the help of the following command

chown -R <current_user> <repo_folder>

with this solution, you can fix the Fatal: detected dubious ownership in repository error.

Conclusion

Both solutions can help you fix the ‘fatal: detected dubious ownership in repository’ error. The change directory ownership method is the best solution as it is without any risk. The add safe directory is also a way to fix the error, but there are a few things you need to consider before that.

With this, I leave the decision to you to follow either way to fix the issue. I hope it helps!

You can comment below to let us know your feedback!

Posted in Git

Leave a Reply

Your email address will not be published. Required fields are marked *