git checkout error: unable to create file git checkout error: unable to create file windows windows

git checkout error: unable to create file


I experienced similar problems when checking out a project into a Windows directory that had a 67- (Windows) or 76- (cygwin) character base path - when added to the path-length of the checked out files, it exceeded Windows' path-length limit:

git checkout -f HEADerror: unable to create file <194-character filepath> (No such file or directory)fatal: cannot create directory at '<187-character directory path>': No such fileor directory

I solved the problem by checking out the git repository to c:\git, which, at 6 or 15 characters in length, kept the maximum path-length under the Windows limit.


Try:

git config --system core.longpaths true

This will allow it to checkout the files even with longer filepaths. The issue with this would be when you try to delete it, as Windows will not allow to delete a path longer than it's allowed threshold. The workaround to that is to rename the folders in the local repository, so that the overall length of the path is lessened. For example, a path that is alpha/beta/gamma/universe.txt, can be limited to 1/2/3/universe.txt, so that it's length is under the windows filesize threshold.


Many Windows APIs are limited to 260 symbols for file path name. So git can't create files with names longer than 260 symbols. NTFS file system actually supports longer names (32k) but there is no easy way to allow long names for programs.

Workaround 1: move your project to a new location, closer to disk root.Advantage:

  • Everything should work fine (assuming there no files with path longer 260)

Disadvantage:

  • You have to change project location

Workaround 2: create a Junction to your project folder from a folder that is closer to disk root and do git clone from the junction folder. You can do this with mklink command or Link Shell Extension.

Advantage:

  • You can have long file names (greater than 260)
  • You can preserver project location
  • You may safely delete junction after initial cloning (if you don't need to work with files that violate 260 symbol limit at original location)

Disadvantage:

  • Full file name at junction still have to be less 260 symbols. Otherwise this solution will not help.
  • If you want to modify the files with long