128

I'm using Windows as my OS, and working on a project with a friend who's using a Mac. He checked in code to our Github.

I was trying to git pull everything he did and it aborted with "filename too long" errors of 3rd party code.

What can I do?

wonea
  • 4,783
  • 17
  • 86
  • 139
Dave Martin
  • 1,387
  • 2
  • 10
  • 8
  • That problem has two principally different cases, depending on your operation. If the repository already exists, you can edit its configuration. But if not? For cloning/checkout with creation a new directory only the answer of @AlexRosenfeld will help. – Gangnus Jan 20 '17 at 11:21

7 Answers7

224

The msysgit FAQ on Git cannot create a filedirectory with a long path doesn't seem up to date, as it still links to old msysgit ticket #110. However, according to later ticket #122 the problem has been fixed in msysgit 1.9, thus:

  1. Update to msysgit 1.9 (or later)
  2. Launch Git Bash
  3. Go to your Git repository which 'suffers' of long paths issue
  4. Enable long paths support with git config core.longpaths true

So far, it's worked for me very well.

Be aware of important notice in comment on the ticket #122

don't come back here and complain that it breaks Windows Explorer, cmd.exe, bash or whatever tools you're using.

phoenix
  • 717
  • 1
  • 8
  • 26
mloskot
  • 37,086
  • 11
  • 109
  • 136
  • There are a few updates, looks like there is some additional script you need to run after installing mysysgit https://github.com/msysgit/git/pull/122#issuecomment-43653756 – Adam Grant Aug 01 '14 at 18:36
  • 22
    What actually worked for was: git config --global core.longpaths true – Anton Andreev Sep 01 '15 at 21:45
  • @AntonAndreev Yup, if you wish to set it in global scope, that's OK. Local scope per repository is perfectly valid as well. – mloskot Sep 01 '15 at 22:11
  • It did not work for me without setting it at the global level. – Anton Andreev Sep 01 '15 at 22:21
  • @AntonAndreev The msysgit docs do not say anything that the core.longpaths work at global level only, on the contrary, it shows example at repo level https://github.com/msysgit/msysgit/wiki/Git-cannot-create-a-file-or-directory-with-a-long-path If it does not work for you, I'd suggest to report a bug to msysgit. – mloskot Sep 02 '15 at 09:13
  • I faced with interesting behaviour in atlassian stash. It could not merge pull request but also could not say what's wrong with PR. Trying to checkout branch locally, I've faced with this issue, removed file, committed, and Atlassian Stash removed PR's conflict label. Thank you for your explaination, it was really handy – Alexander.Iljushkin Feb 10 '16 at 10:44
  • 1
    That way won't work for cloning/checkout with creation a new directory. Only the answer of @AlexRosenfeld will help. – Gangnus Jan 20 '17 at 11:18
80

Solution1 - set global config, by running this command:

git config --system core.longpaths true

Solution2 - or you can edit directly your specific git config file like below:

YourRepoFolder -> .git -> config:

[core]
    repositoryformatversion = 0
    filemode = false
    ...
    longpaths = true        <-- (add this line under core section)

Solution3 - when cloning a new repository: here.

Community
  • 1
  • 1
Daniel Hári
  • 7,254
  • 5
  • 39
  • 54
34

A few years late, but I'd like to add that if you need to do this in one fell swoop (like I did) you can set the config settings during the clone command. Try this:

git clone -c core.longpaths=true <your.url.here>
vvvvv
  • 25,404
  • 19
  • 49
  • 81
xandermonkey
  • 4,054
  • 2
  • 31
  • 53
14

Open your.gitconfig file to add the longpaths property. So it will look like the following:

[core]
symlinks = false
autocrlf = true
longpaths = true
Pete
  • 582
  • 5
  • 8
  • 1
    That way won't work for cloning/checkout with creation a new directory. Only the answer of @AlexRosenfeld will help. – Gangnus Jan 20 '17 at 11:19
9

On windows run "cmd " as administrator and execute command.

"C:\Program Files\Git\mingw64\etc>"
"git config --system core.longpaths true"

or you have to chmod for the folder whereever git is installed.

or manullay update your file manually by going to path "Git\mingw64\etc"

[http]
    sslBackend = schannel
[diff "astextplain"]
    textconv = astextplain
[filter "lfs"]
    clean = git-lfs clean -- %f
    smudge = git-lfs smudge -- %f
    process = git-lfs filter-process
    required = true
[credential]
    helper = manager
**[core]
    longpaths = true**
Kumar Abhishek
  • 3,004
  • 33
  • 29
8

As someone that has ran into this problem constantly with java repositories on Windows, the best solution is to install Cygwin (https://www.cygwin.com/) and use its git installation under all > devel > git.

The reason this is the best solution I have come across is since Cygwin manages the long path names so other provided commands benefit. Ex: find, cp and rm. Trust me, the real problem begins when you have to delete path names that are too long in Windows.

Tristan
  • 661
  • 9
  • 15
6

Try to keep your files closer to the file system root. More details : for technical reasons, Git for Windows cannot create files or directories when the absolute path is longer than 260 characters.

Michael Ver
  • 402
  • 3
  • 5
  • It seems like it can only go to 130 [maybe windows uses double byte unicode characters underneath] by default [?] – rogerdpack Jul 09 '14 at 17:16
  • 8
    More people should be pushing Microsoft to change this restriction (and fix the legacy APIs they break). There is no reason we should still be living with this remnant of days when file names were restricted to <8>.<3> characters. By not fixing it immediately, a bigger hole is being dug. Fix the slash direction while you are at it. – cchamberlain Jul 08 '15 at 06:44
  • @cchamberlain C:/foo/bar/baz is perfectly valid, though while \foo\bar\baz is also valid (it will refer to whatever logical drive the current working directory is on) /foo/bar/baz may cause ambiguity with command-line flags. – JAB Sep 07 '15 at 14:55
  • @JAB - It is true that forward slash works sometimes but as you pointed out it's not reliable. cmd.exe will react one way and powershell another. Autocomplete breaks. The underlying API understands it but cmd.exe does not in all cases and the safer use of backslash causes strings to sometimes need escaping. There is already enough command line backslash garbage with the number of spaces and parentheses that exist in common Windows paths. – cchamberlain Sep 08 '15 at 01:05
  • 2
    It is not a solution. Technology should be servant of man, not man should be servant for technology. – Daniel Hári Dec 22 '15 at 14:41
  • 1
    [Windows 10](https://mspoweruser.com/ntfs-260-character-windows-10/) allow [paths longer than 260 characters](http://stackoverflow.com/q/27680647/995714). In previous versions of Windows use [`\\?\\` prefix](http://superuser.com/a/811155/241386) – phuclv Oct 28 '16 at 07:55