I mounted a new hdd in my linux workstation. It looks working well. I want to download some repo in the new disk. So I execute git clone XXX
, and it works well. But when I cd in the folder, and execute git submodule update --init --recursive
. It failed with
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 thought maybe it’s just a slight warning, so I just executed git config --global --add safe.directory /media/data/users/jhu3szh/serialize
. However, when I execute the git submodule again, more similar errors came out. There are many submodules in repo.
Can someone give me some explanation of what happened?
20
Answers
Create a new directory on your disk where your current user is the owner of this new directory. In this new directory clone your git repo.
I got same issue and fixed by changing owner for directory.
Please try
chown -R <current_user> <repo_folder>
Make sure you are using the correct terminal user. For me I had temporarily changed to the root user which would have caused issues. Changed back to standard user with
su git-user
and error went away.Silence all
safe.directory
warningstl;dr
Silence all warnings related to git’s
safe.directory
system. Be sure to understand what you’re doing.Long version
Adapted from this post on I cannot add the parent directory to safe.directory in Git.
I had the same issue and resolved it by disabling safe directory checks, which will end all the "unsafe repository" errors.
This can be done by running the following command1:
Which will add the following setting to your global
.gitconfig
file:Before disabling, make sure you understand this security measure, and why it exists. You should not do this if your repositories are stored on a shared drive.
However, if you are the sole user of your machine 100% of the time, and your repositories are stored locally, then disabling this check should, theoretically, pose no increased risk.
Also note that you can’t currently combine this with a file path, which would be relevant in my case. The command doesn’t interpret the wildcard
*
as an operator per say– it just takes the"*"
argument to mean "disable safe repository checks/ consider all repositories as safe".1 – If this fails in your particular terminal program in Windows, try surrounding the wildcard with double quotes instead of single (Via this GitHub issue):
git config --global --add safe.directory "*"
If same problem occurs on NTFS/Windows, make sure both parent of .git and .git folders are owned by exact user you run git from.
Just same group (Administrators) or only parent of .git may not work.
Upd: Permissions can be edited via right-click on the folder(s) → Properties → Security Tab → Advanced (bottom right of the window) → Owner.
Possibly disabling inheritance will be required, done in same window. This q/a have hints.
User you run git from can be checked in Resource Monitor: Task Manager → Performance → Open Resource Monitor (on bottom). May require enabling hidden "User Name" column.
Just run using sudo : sudo git status
I had the problem with a library from the vendor folder. I just deleted the folder of the library and reinstall it.
I’ve got the same error message on Ubuntu/LEMP when executed git’s commands from PHP. Nothing suggested above helped to fix problem.
Solution:
You need to set correct owner of the hidden ‘.git’ folder.
In my case git comands was executed by ‘www-data’ user (which is a web-server user):
To restore ability to work with git from command line you need to allow group to write:
For anyone having this problem in phabricator here is the solution that worked for me.
Background: Phabricator was working fine for me until this happened. When I open any repository to get the clone URL it throws me this error:
Solution: I checked the permissions and ownership of dir /var/repo which was my current user. Phabricator web-server executes the commands using user "www-data".
I then changed the ownership of the "/var/repo" dir to the following:
After that it worked fine.
If the SO is Windows, you have to take the owner of the file with the command
/F
parameter is the file, with the * wildchar will apply to all files and folder;/R
parameter means recursive, it’s apply the owner to the current logged user to all files and subfolders tooIf the command you are running already failed once or there was a previous version of the package in the install folder, try removing the corresponding package’s folder before trying again or look for further solutions. Here,
jhu3szh/serialize
for example if it corresponds to your package name.It should be possible to restore the ownership. For example:
Related: ensure_valid_ownership()
My problem was that I was not running as
sudo
. I usually set at the beginningsudo bash
and do not think aboutsudo
command. So it made me a lot of headache before I realized that I skipped my common step.I ran below command on
git bash
to solve itClose and reopen VS Code if required.
Just do your command from sudo rights like :
sudo git clone XXX
Encountered
fatal: detected dubious ownership in repository at
using Fork client on Windows against repository in WSL.Solution was to open git console inside Fork (pointing at git windows client used by Fork) and execute:
Running command inside WSL simply not worked as it changes
.gitconfig
inside the WSL.This error is raised when you make an attempt to git initialize (and then run any other git command) a folder that is not child of
/home/my_user/
.In your case, the folder is
serialize
, which is under/media/...
.You can stop the alert form being raised by just moving the folder under
/home/my_user/
.Otherwise, you can also change the owner of
my_project_folder
, as @Prakash Sahoo suggests.If you are lost, git clone the file with different usernames, for example try with
sudo git clone
, this gives ownership toroot
, if you choose instead justgit clone
… then the ownership goes to the currentusername
…one of them should work, likely you are mixing them up and you need to typesudo git branch -a
to avoid this error.Happened to me after upgrading JetBrains Rider code editor. Before the upgrade Rider was launched by a shortcut as Administrator. Upgrade removed the shortcut’s config of "Run as Admin" which caused Rider’s Terminal to start giving me this git error. Running the application (Rider) as Admin again solved the git issue.
Open git bash in your project Location and run below command for Windows OS for bypass security.
git config –global safe.directory ‘*’