Error updating changes detected dubious ownership

Know how to deal with the “fatal: detected dubious ownership in repository” error related to git with different reasons and solutions through this article. Read on it now.

Fatal: detected dubious ownership in repository” is a common error related to the unsafe repository in Git. In this article we will show you the cause of this error and the way to use a safe.directory to fix it.

How does the error “fatal: detected dubious ownership in repository” happen?

This error happens due to the many following reasons:

Firstly, it might be because you are trying cloning from another user. When accessing /var/www, such as when performing a Git command, a Git user often gets this error. This is because /var/www is owned by www-data, who is not a sudo user, and so access is restricted:

Secondly, you are using an Ubuntu user and an outdated version of Git. We will help you update git, but first and foremost, you should check the git version you are using:

Finally, you are attempting to insert the disk into a Linux workstation and try to get a new repository on the new disk. For example:

git submodule update –init –recursive

How to solve the error?

Solution 1: Add a safe.directory

To solve “fatal: detected dubious ownership in repository” error, if because of the Git safe update, you will have to add into the safe directory the project directory with this command:

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

Or you can use this command to add all directories to the safe directory (this is not recommended):

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

You shouldn’t disable this security measure unless you understand why it was implemented and why it would still be needed. Ideally, your repositories should be stored on a drive exclusively yours and not shared.
Disable this check if you only use your machine 100% of the time and store your repositories locally. This theoretically wouldn’t increase any risk. If the command above causes errors, you are not using an up-to-date Git version, so you have to update before using it. Check out our next solution to update Git.

Solution 2: Update Git version

Any “unsafe repository” errors will stop with the latest patch versions of Git v2.30-34. You can solve the problem by disabling safe directory checks in Git v2.35.3. To update git in Windows:

winget install --id Git.Git -e --source winget

To update git in Ubuntu or WSL, first, run:

Now you can install the latest version of git by this command:

Solution 3: Change owner or Switch user

When attempting to clone from a different user, you should change this owner with the command:

chown -R <current_user> <repo_folder>

Or, use this command to switch to the correct user:

su here_currect_user_name

Summary

We have shown you how to deal with the “fatal: detected dubious ownership in repository” in Git. You can quickly solve this problem by checking Git ownership or Git settings carefully and finding out the reasons causing this problem in this tutorial.

Maybe you are interested:

  • How to delete folder in Gitlab repository
  • Git commit your changes or stash them before you can merge
  • How to skip Git commit hooks

I’m Edward Anderson. My current job is as a programmer. I’m majoring in information technology and 5 years of programming expertise. Python, C, C++, Javascript, Java, HTML, CSS, and R are my strong suits. Let me know if you have any questions about these programming languages.


Name of the university: HCMUT
Major: CS
Programming Languages: Python, C, C++, Javascript, Java, HTML, CSS, R

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.

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.

While I am trying to push my commit I am facing some unwanted error and the error is saying that fatal: detected dubious ownership in repository So Here in This article, We will Discuss how I solved this error. And what are the possible causes of this error?

Contents

  • 1 How to Fix fatal: detected dubious ownership in the repository?
  • 2 Solution 1: Add Your Directory to safe Directory
    • 2.1 Also, Read

How to Fix fatal: detected dubious ownership in the repository?

You can check Git Post Related safe.directory You are all facing this warning is related to git’s safe.directory system You need to run the following command to solve all unsafe repo’s warning. Jusr tun this following command in your tereminal: git config –global –add safe.directory ‘*’ If You are still facing any error then You need to put double quotes instead of single quotes Just like this: git config –global –add safe.directory “*” And this safe directory command will add safe directory section in your .gitconfig file. and Now, You will no longer face the above error.

fatal: detected dubious ownership in the repository

You can check Git Post Related safe.directory You are all facing this warning is related to git’s safe.directory system You need to run the following command to solve all unsafe repo’s warning. Jusr tun this following command in your tereminal: git config –global –add safe.directory ‘*’ If You are still facing any error then You need to put double quotes instead of single quotes Just like this: git config –global –add safe.directory “*” And this safe directory command will add safe directory section in your .gitconfig file. and Now, You will no longer face the above error.

Solution 1: Add Your Directory to safe Directory

You can check Git Post Related safe.directory You are all facing this warning is related to git’s safe.directory system You need to run the following command to solve all unsafe repo’s warning. Jusr tun this following command in your tereminal.

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

If You are still facing any error then You need to put double quotes instead of single quotes Just like this.

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

And this safe directory command will add a safe directory section in your .gitconfig file. and Now, You will no longer face the above error.

Also, Read

  • Failed! Error: SET PASSWORD has no significance for user ‘root’@’localhost’ as the authentication method used doesn’t store authentication data in the MySQL server
  • Invalid syntax in configuration ini file.
  • A listener indicated an asynchronous response by returning true, but the message channel closed before a response was received
  • How to fix “zsh: command not found: python” error? (macOS Monterey 12.3, python 3.10, Atom IDE, atom-python-run 0.9.7)

Platform Notice: Cloud Only — This article only applies to Atlassian products on the cloud platform.

   

Summary

When trying to execute a git command in a repository, such as a clone or push, git returns a fatal error saying the repository has dubious ownership and the git command is aborted.

Diagnosis

After executing a git command, an error similar to below is returned : 

fatal: detected dubious ownership in repository at '<path to the repository>'
To add an exception for this directory, call:
git config --global --add safe.directory <path to the repository>

or

fatal: unsafe repository ('<path to the repository>' is owned by someone else)
To add an exception for this directory, call:

git config --global --add safe.directory <path to the repository>

Cause

A change was introduced in git 2.35.2 (and newer) to prevent a user from executing git commands in a repository owned by a different user. This is to address a security risk, CVE-2022-24765,  for more details see setup_git_directory and Git security vulnerability announced. The change to setup_git_directory prevents git invocations from executing commands on a repository owned by another user.

Solution

On a single user system

Change the owner of the repository folder to the user which is running the git command. 

For Windows : One way to do this is with the takeown command:

takeown /f <path to the repository> /r /d y

For Linux: Using the chown command : 

chown -R username:group <path to the repository>

Single repository on a multi user system: 

The default solution to workaround this issue would be to add the directory in question to git’s safe.directory list, as the following command :

git config --global --add safe.directory <path to repository>

This is usually the command suggested by git in the error message to add this directory to the exception list.

Multiple repositories, system global settings: 

Add the folder to the safe.directory list at the system level

git config --system --add safe.directory <path to the repository>

If using git > 2.36, there’s also a wildcard to add all folders to safe.directory list :

git config --global --add safe.directory '*' # For the current user and all repositories
git config --system --add safe.directory '*' # For all users and all repositories

Before adding paths/repositories to the exception list, please make sure to understand the security implications of CVE-2022-24765 and setup_git_directory. To avoid this, it’s strongly recommended for each user have their own clone of the 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.

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.

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!

To Solve fatal: detected dubious ownership in repository Error You need to disable checks and it will end all the unsafe repository errors in GitHub. In this article, We are going to learn about How to reproduce this error and we will discuss All Possible Solutions Let’s Get Start With This Article.

Contents

  1. Solution 1: add safe directory
  2. Frequently Asked Questions
  3. Conclusion

Solution 1: add safe directory

To Solve fatal: detected dubious ownership in repository Error You need to disable checks and it will end all the unsafe repository errors. But Before Disabling it Just Read This Why This error is Exist and then You can disable it by running this command in your terminal.

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

By Running git config –global –add safe.directory ‘*’ command it will add this line in your .gitconfig file.

[safe]
    directory = *

And now, Your error will be solved. Thanks.

Frequently Asked Questions

  1. How To Solve fatal: detected dubious ownership in repository Error?

    To Solve fatal: detected dubious ownership in repository Error You need to disable checks and it will end all the unsafe repository errors. But Before Disabling it Just Read This Why This error is Exist and then You can disable it by running this command in your terminal: git config –global –add safe.directory ‘*’ By Running git config –global –add safe.directory ‘*’ command it will add this line in your .gitconfig file: [safe] directory = * And now, Your error will be solved. Thanks.

  2. fatal: detected dubious ownership in repository

    To Solve fatal: detected dubious ownership in repository Error You need to disable checks and it will end all the unsafe repository errors. But Before Disabling it Just Read This Why This error is Exist and then You can disable it by running this command in your terminal: git config –global –add safe.directory ‘*’ By Running git config –global –add safe.directory ‘*’ command it will add this line in your .gitconfig file: [safe] directory = * And now, Your error will be solved. Thanks.

Conclusion

You need to add a safe directory and it will resolve your error. I hope this article helped you. Comment below on which solution worked for you.

Also, Read

  • Creating a personal access token in Github
  • Please use a personal access token instead in GitHub
  • command github.copilot.generate not found GitHub Copilot

Понравилась статья? Поделить с друзьями:
  • Error update or delete on table violates foreign key constraint
  • Error update aborted при прошивке видеокарты
  • Error update aborted перевод
  • Error update aborted nvflash
  • Error unused parameter