9

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
torek
  • 448,244
  • 59
  • 642
  • 775
Matthias Pospiech
  • 3,130
  • 18
  • 55
  • 76
  • 7
    On WIndows, you generally must use double quotes, not single quotes, to quote things. Check to see if `safe.directory` is set to `*` (correct) or to `'*'` (wrong). If it's wrong, edit your global config file to remove the single quotes. I'm also assuming you have a current Git (there was a set of versions that didn't support the `*` setting for a while). – torek Aug 19 '22 at 12:59
  • .gitconfig (global) ist now: `[safe] directory = *` The error does not occur anymore. However, I still do not know where to set the environmental variable. – Matthias Pospiech Aug 20 '22 at 06:40
  • I don't use Windows, but I believe that on Windows CMD.EXE you use the `set` command to set things that then wind up as environment variables. If you use the Windows port of bash distributed with Git-for-Windows, you can run commands as `ENV_VAR=value cmd arg1 arg2` for instance and the setting will be in effect for just that one run, or you can run `export ENV_VAR=value` as a command and the setting is now set for the remainder of the shell session (or until you `unset ENV_VAR`). – torek Aug 20 '22 at 07:51
  • For TortoiseGit questions, ask the TortoiseGit folks. – torek Aug 20 '22 at 07:51
  • @torek: TortoiseGIT is only a frontend to git. The settings must all be done for git. The message displayed in the windows is exactly the same as the one that git displays on the commandline. If I use this gui or not has nothing to do with this problem. The only thing that is important is the OS which is windows. – Matthias Pospiech Aug 20 '22 at 16:15
  • @torek: The commandline on windows has the command `set` which displays all environment variables. Adding the new one is done by `set GIT_TEST_DEBUG_UNSAFE_DIRECTORIES=true`. – Matthias Pospiech Aug 20 '22 at 16:19
  • `git config --global --add safe.directory "*"` and then `git config --global --list` to check – user3443139 Dec 17 '22 at 09:00

2 Answers2

12

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.

scx
  • 3,221
  • 1
  • 19
  • 37
  • 2
    If the Windows SID (Security Identifier) is different between the local Windows machine and the Network Attached Storage (NAS) device - for example there's no Domain Controller (DC) or the two machines are in different Domains - then you will get this error. It cannot be fixed by changing the owner of the file unless the NAS and Windows machines are sharing user credentials through a DC's Active Directory system. For example the Synology NAS has an Active Directory package available which could be deployed to provide Windows credentials to all clients. – user3443139 Dec 17 '22 at 08:59
  • 1
    @user3443139 Yes, that's why "If you intend to use more than one user on a cloned repo, then I'd follow git instructions to add the exception." ;) This question is the top google question about this issue. – scx Dec 18 '22 at 15:57
  • 2
    I think you missed the point here :) This will occur with a single user (one person) using a git repository on a network share (NAS) over CIFS, unless you have a Domain Controller (or equivalent) to provide a single user credential (SID) to all machines involved (NAS + client PC in OP's question). – user3443139 Dec 18 '22 at 21:06