Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git for windows 2.35.2 can not add exception safe.directory

Tags:

git

windows

I am using git version 2.35.2.windows.1 on my win10. My project is stored in my NAS running Ubuntu. I set up an SMB remote disk using samba, and do all necessary work on win10.

After the 2.35 update, i got

fatal: unsafe repository ('//192.168.1.120/sambashare/x' is owned by someone else) To add an exception for this directory, call:

git config --global --add safe.directory //192.168.1.120/sambashare/x

And after i did as instructed, git threw a warning said: warning: encountered old-style '//192.168.1.120/sambashare/x' that should be '%(prefix)//192.168.1.120/x'

I tried to tweak the directory string a little (like changing it to Z://x, Z://192.168.1.120/x, etc.), but that is of no avail.

my git config file looks like: [safe] directory = //192.168.1.120/sambashare/x , and i am not quite sure what to do to fix this problem.

For now, i am doing all my git work via ssh. Thx in advance for any potential solution.

like image 488
LNseyJt2X-24UJ4r7KTL Avatar asked Dec 31 '25 23:12

LNseyJt2X-24UJ4r7KTL


1 Answers

  1. The prefix must include the trailing /. Literally like this: %(prefix)/.
  2. Whether you must use hostname, IP address or FQDN depends on how you mounted the network share.

Run net use to list the exact remote paths of mounted shares.

Working examples

If the network share was mounted as \\123.123.123.123\repoA run

git config --global --add safe.directory %(prefix)///123.123.123.123/repoA

If the network share was mounted as \\servername\repoB run

git config --global --add safe.directory %(prefix)///servername/repoB

If the network share was mounted as \\servername.company.com\repoC run

git config --global --add safe.directory %(prefix)///servername.company.com/repoC

Alternatively you can edit the config with git config --global --edit to the following

[safe]
    directory = %(prefix)///123.123.123.123/repoA
    directory = %(prefix)///servername/repoB
    directory = %(prefix)///servername.company.com/repoC
like image 113
michaelosthege Avatar answered Jan 02 '26 13:01

michaelosthege



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!