Learn how to solve "commit failed, filename too long" error on git Windows.

Problem

Windows does not properly support files and directories longer than 260 characters. This applies to Windows Explorer, cmd.exe,GitHub for windows and many other applications (including many IDEs as well as bash, perl and tcl that come with Git for Windows). For that reason, the long paths support in Git for Windows is disabled by default. You can read more about the 260 characters limit in windows here.

If you open the log, an error with the following description should be listed :

14:02:42.8556|WARN|thread: 1|StandardUserErrors|Showing user error Failed to create a new commit.
GitHub.IO.ProcessException: fatal: unable to stat 'plugins/toolongname/example/app/platforms/toolongname/toolongname/build/intermediates/classes/debug/org/toolongname/toolongname/toolongname$toolongname$toolongname.class': Filename too long

As you can see, indeed the filename (or path) has more than 260 characters, Git has a limit of 4096 characters for a filename, but on windows when the git client is compiled with msys (for example the official GitHub application for windows), it uses an older version of the windows api and there's a limit of 260 characters for a filepath.

Solution

Open the Github Powershell or cmd.exe (you need to have git as an environment variable) and execute the following command :

git config --system core.longpaths true

As we are changing the configuration of git, you can execute it directly in your project or from any path if the Git variable is available.

Git config --system core.longpaths true

The change should be executed immediately and you can procceed with the commits from the command line or even with the GitHub application, have fun !


Senior Software Engineer at Software Medico. Interested in programming since he was 14 years old, Carlos is a self-taught programmer and founder and author of most of the articles at Our Code World.

Sponsors