TroubleChute Logo

Fix Filename too long

Published: Jan 15, 2023
Last Edit: Jan 17, 2023
Git Tips
354 Words, 2 Minutes.

Watch the video:

0:00 - Intro
0:28 - Moving files to a lower path (workaround)
0:53 - The Windows path limit
1:06 - Enable Longpaths on Windows
1:30 - Enable Longpaths for git (4096 chars)

The error

Are you an avid GitHub or Git user on Windows and frequently getting “filename too long” errors? You’re not alone. Windows has a rather short file name limit by default, but there’s a simple solution to this problem.

One way to fix the issue is to move the affected files from a nested folder to the root of your drive. For example, moving a file from your desktop to the root of your C drive. However, if your files are nested too deep in different folders or have names that are too long, this solution may not work.

The issue is caused by a limitation of 260 characters for a file path in the Windows API. But in Windows 10 and above, we can lift the max path limitation. By running a specific PowerShell command as an administrator, we can change the max path limitation from 260 to a much higher number.

Enabling Longpaths on Windows

There are two options. Entering the following into an Administrative PowerShell terminal:

New-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem" `
-Name "LongPathsEnabled" -Value 1 -PropertyType DWORD -Force

or saving the following as a .reg file, and running it to manually create the registry entry yourself:

Windows Registry Editor Version 5.00


Once you’ve done either of these it’s now enabled, assuming you have Windows 10 or above.

Having paths longer than this is disabled by git to prevent people creating paths that are just too long, but if you’re using a repo that has longer paths, you need to enable it in your git as well to handle these new filepaths.

Enable Longpaths in Git

Run the following command in a cmd terminal or powershell terminal:

git config --system core.longpaths true

Now you’re free to run your commands again that caused issues, whether checking out or simply pulling updates.

You now have a file path limit of 4096 characters.

TCNO TechNobo / TroubleChute © Wesley Pyburn (TechNobo / TroubleChute)