How to Fix the Filename Too Long Error in Git

Some projects have a pre-requisite to add file names that are too long, you know, there could be use cases that require a file to test max capabilities. But when you are dealing with such files in Git, you might end up getting an error that says: ‘filename too long’

This is happening because, for file names, Git has a limit of 4096 characters. However, on Windows, the Git limit for file names is just 260 characters owing to it being compiled with msys. Anything beyond that and you might get the aforementioned error. Hence it is more like a Windows-specific issue.

To tackle such a situation you can make use of the core.longpaths setting. It is not turned on by default. So you have to manually make this true. That should solve the problem. The question is now how to do that?

meme on git

How to Fix the File Name is Too Long Git Error

Here are the steps on How to Fix the Filename too long error in Git:

Step 1: Open git bash as an Administrator by clicking on the Start or Search button and typing Git Bash. Click on the Run as administrator option.

git bash run in administrator mode

Step 2: Type the following command and press Enter

git config --system core.longpaths true

The usage of the –system flag here insinuates the setting will be applied system-wide for all users.

the actual command for longpaths true

Alternatively, if the above doesn’t work you can replace –system with –global. So the command becomes:

git config --global core.longpaths true

The –global flag here means that the changes will be applied to the user’s global settings.

NOTE: If you don’t want the configuration setting to be applied globally or system-wide, but rather want to be only current project specific, you can skip the –system or –global part. So the command will be just.

git config core.longpaths true

Well at first it might seem that nothing might have happened, but actually in the internal configurations the deed has been done.

Now go ahead and do your regular pull, or push whatever you were doing when you got this error.

Alternate Method to Fix the Filename Too Long Error in Git

Another alternative to approach the actual logic of updating core.longpaths is to make the changes directly into the regedit.

Step 1: Open Windows Powershell using the same approach. Go for the Run it as administrator option again.

windows powershell run in admin mode

Step 2: Type the following setting to verify the status on longpaths:

Get-ItemProperty HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem -Name LongPathsEnabled

and press Enter.

command to check longpaths enabled or not

The Item Property will be retrieved.

If the LongPathsEnabled value is 0, it means that it is set to false. To make it true you have to set it to 1.

Step 3: Type the following and press enter.

$MyPSexe = Get-Process -PID $PID | % Path
Start-Process -Verb RunAs $MyPSexe "-c","Set-ItemProperty HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem -Name LongPathsEnabled -Type DWord -Value 1"

Now you might need to restart your system in order for the above change to take effect.

That’s it! These are the two methods to make sure that you can easily get rid of the Filename is too long error.

Scottshak

Poet. Author. Blogger. Screenwriter. Director. Editor. Software Engineer. Author of "Songs of a Ruin" and proud owner of four websites and two production houses. Also, one of the geekiest Test Automation Engineers based in Ahmedabad.

You may also like...

Leave a Reply