Matthias Pospiech
Matthias Pospiech

Reputation: 3488

git: fatal: detected dubious ownership

I work with a new Windows installation and the same folder on my network share (NAS System). After installing git and tortoisegit I tried to connect to the git repository, but I always get this error. What has changed is the server and not the user.

enter image description here

I have run

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

But that changes nothing. How can I fix this?

Where can I set the variable

GIT_TEST_DEBUG_UNSAFE_DIRECTORIES=true

Upvotes: 31

Views: 65967

Answers (7)

dtanon
dtanon

Reputation: 1

for windows users with Ubuntu for windows, The commands has to be lounch from windows terminal for exemple powershell

Upvotes: 0

Dmitrii Fediuk
Dmitrii Fediuk

Reputation: 410

takeown /f "<path>" /r /d y

Enables an administrator to recover access to a file that previously was denied, by making the administrator the owner of the file. This command is typically used on batch files*

https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/takeown

Upvotes: 8

Eduardo
Eduardo

Reputation: 73

Just to complement on the answers above for total noobs like me: For me I got this error because I created the folder and many other files in command prompt running as an admin (was working with django and virtual envs), so get into command prompt as an admin (again), and follow the instructions stated by github (in my case)

git config --global --add safe.directory C:/Users/your_user_name/your_directory

Upvotes: 1

Tom Parker
Tom Parker

Reputation: 11

I encountered this as well. The problem was that, when I created the bare repository, I did so while running the command shell "as Administrator". That assigned ownership of the .git file to the Admin. Then, when trying to execute commands as a normal user (ie: git pull, etc.), it gives the error.

The solution is to create the bare repository as a normal user.

Upvotes: 1

AFract
AFract

Reputation: 9700

I have just encountered the same error with a repository that was moved from a NTFS volume (managed by TrueCrypt or VeraCrypt) to another volume that was not in NTFS.

I have just created again the volume in NTFS, moved the repository on the new volume, and it was fine. So apart user identity, the file system and permissions associated is an important when moving a repository.

Upvotes: 0

Jon Gan
Jon Gan

Reputation: 179

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

This worked for me, minor difference.

Upvotes: 12

scx
scx

Reputation: 3947

This happens when a repo was cloned by a different user than your current user. In my case, I've encountered this issue after reinstalling windows, but using previously cloned git repositories (on a separate partition).

  • Right-click repo folder, properties, security, advanced.
  • Click "Change" on the Owner line.
  • Find your user (advanced..., find now, select your user). Confirm.
  • On the change screen, enable "Replace owner on subcontainers and objects".

That should fix the error.

If you intend to use more than one user on a cloned repo, then I'd follow git instructions to add the exception.

Upvotes: 48

Related Questions