1

Getting following error/warning when I clone a large project in my Windows 10.

....
error: unable to create symlink Codes/MyProject/Pods/Headers/Public/nanopb/pb_common.h: No such file or directory
error: unable to create symlink Codes/MyProject/Pods/Headers/Public/nanopb/pb_decode.h: No such file or directory
error: unable to create symlink Codes/MyProject/Pods/Headers/Public/nanopb/pb_encode.h: No such file or directory
Updating files: 100% (9536/9536), done.
fatal: unable to checkout working tree
warning: Clone succeeded, but checkout failed.
You can inspect what was checked out with 'git status'
and retry with 'git restore --source=HEAD :/'

Why the warning appears and how to resolve this?

However, I tried to run following command from the downloaded repo root directory as per gits suggestion,

git restore --source=HEAD :/

But again I got similar error like,

    ....
    error: unable to create symlink Codes/MyProject/Pods/Headers/Public/nanopb/pb_common.h: No such file or directory
    error: unable to create symlink Codes/MyProject/Pods/Headers/Public/nanopb/pb_decode.h: No such file or directory
    error: unable to create symlink Codes/MyProject/Pods/Headers/Public/nanopb/pb_encode.h: No such file or directory
Sazzad Hissain Khan
  • 37,929
  • 33
  • 189
  • 256
  • Could be a problem with case-(in)sensitive file systems – knittl Dec 31 '21 at 09:23
  • @knittl no idea. How to fix it for windows git bash? – Sazzad Hissain Khan Dec 31 '21 at 09:34
  • 4
    You can't really *fix* this *on* Windows. (Use Linux or WSL to deal with it much more easily.) But if you disable `core.symlinks` you may be able to *work around* it. See [your own question here](https://stackoverflow.com/q/63374527/1256452). – torek Dec 31 '21 at 09:55
  • In my case, the problem was file name too long. It worked for me .. git config --global core.longpaths true – alamin39 Dec 31 '21 at 11:00
  • @torek disabling `core.symlinks` didnt work. I think the problem is different. – Sazzad Hissain Khan Dec 31 '21 at 11:52
  • Enable Windows Long File Names. Which version of Windows are you using? https://learn.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation?tabs=cmd – John Hanley Dec 31 '21 at 17:35
  • @JohnHanley I am using Windows 10. – Sazzad Hissain Khan Dec 31 '21 at 18:45
  • Windows 10 is a product name that covers 6+ years of versions. The link I provided is for version 1607 and later. – John Hanley Dec 31 '21 at 19:52
  • @JohnHanley my windows 10 version is 2004, OS build is 19041.1348 – Sazzad Hissain Khan Jan 01 '22 at 03:54
  • Did you follow my link and retry? – John Hanley Jan 01 '22 at 05:31
  • @JohnHanley the problem was solved using `git config --global core.symlinks false` though. I think if that was for long pathname then the message is supposed to be there in the error logs... like instead of `No such file or directory` it could show `Filename too long` – Sazzad Hissain Khan Jan 01 '22 at 11:40
  • You have disabled a feature instead of fixing/enabling a feature. However, I am glad you solved your problem with your system. Windows supports symbolic links and hard links. There is no good reason to disable them. Your solution is a bandaid that I hope others do not follow. – John Hanley Jan 01 '22 at 18:40
  • @JohnHanley I will soon look into your solution and if it solves I will update the answer. Thanks for your time. – Sazzad Hissain Khan Jan 01 '22 at 18:57

2 Answers2

2

Windows, by default, requires special privileges to create symlinks. This is because when Windows added symlinks, Microsoft was concerned that existing programs would acquire vulnerabilities due to symlinks that were already well known on Unix, and didn't want that to happen automatically. In retrospect, this has made symlinks extremely uncommon on Windows.

However, if you're using Windows 10 or newer, you can enable Developer Mode, which allows symlinks to be created by unprivileged users. I strongly recommend this because symlinks are very useful, but some people cannot do this because their system administrator hasn't allowed it. If this is possible in your case, it will fix the problem.

You can disable symlinks by setting core.symlinks to false. Typically Git does this automatically when cloning a repository on a file system that doesn't support symlinks properly, so you shouldn't normally need to. Note that in many cases, the project will be broken in such a case, because the symlinks are typically present because they're required for things to work.

The other possibility here is that your project has two files or directories that differ only in case and Windows is case insensitive by default. As a result, what should be a symlink in one case is something like a file or directory in another case, and since your system is capable of handling only one case at a time, you can't check both out at once. This is just an unfortunate consequence of how Windows works by default, and you'll need to use an environment that is case sensitive, like Linux or WSL.

bk2204
  • 64,793
  • 6
  • 84
  • 100
0

The problem was solved using following command from Git bash,

git config --global core.symlinks false

Sazzad Hissain Khan
  • 37,929
  • 33
  • 189
  • 256