Filename too long in Git for Windows
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
When working with Git for Windows, many users encounter an issue where Git refuses to handle files because the filename or the path length exceeds Windows' default maximum limit. This problem is typically prompted by the error message "Filename too long" and can be frustrating, especially for those managing large codebases with deep directory structures or long filenames.
Understanding the Path Length Limitation
Windows platforms typically have a maximum path length limit of 260 characters. This limitation stems from the Windows API and historically includes all directory levels plus the file name itself and a null terminating character. This restriction is known in Windows as the MAX_PATH limitation.
Git, initially developed to run on UNIX-like systems (which do not have a strict limit like MAX_PATH), exposed this limitation when ported to Windows. Since files and directories that were perfectly valid on a UNIX system might exceed this length limit on Windows, operations involving such entries can lead to unexpected errors.
The Nature of the Issue in Git
When you clone, pull from a repository, or check out a branch, if any file's absolute path exceeds the 260 character limit, Git may generate errors like:
This error does not only hinder file operations but also complicates tasks like switching branches, applying patches, and more.
Examples of Issues
Consider a project structured as follows:
Here, if the combined length of the path and filename exceeds 260 characters, Git operations involving that path will fail under default Windows setup.
Workarounds and Solutions
1. Configuring Git to Support Long Paths
You can direct Git to handle longer paths by enabling the longpaths configuration. This can be done with the following Git command:
This command modifies the Git configuration at the system level to support long file paths. Note, however, that this might not resolve all issues related to Windows' intrinsic MAX_PATH limit, but it can mitigate many problems related to Git functionality.
2. Modifying Windows Group Policy
For Windows 10 version 1607 and later, you can enable paths longer than 260 characters by modifying the group policy:
- Type
gpedit.mscin the Start menu to open the Local Group Policy Editor. - Navigate to
Local Computer Policy > Computer Configuration > Administrative Templates > System > Filesystem. - Double-click on the "Enable NTFS long paths" setting.
- Set it to "Enabled" and apply the changes.
This changes the maximum path length limit (effectively enabling very long paths), though some applications might still fail to handle longer paths correctly.
3. Shortening Paths Manually
While it's more of a workaround than a solution, restructuring your directories or renaming files to reduce their depth or length can sometimes be the fastest way to solve path length issues, especially when dealing with older tools or scripts that cannot handle long paths.
Conclusion and Best Practices
Handling long file paths in Git for Windows requires a blend of configuring Git itself, adjusting system settings, and sometimes simply revising your file-naming and directory structuring practices.
Here's a summary of the key options available:
| Solution | Description |
git config --system core.longpaths true | Enables Git's support for handling longer file paths |
| Enable NTFS long paths in Group Policy | Allows Windows and Windows applications to handle longer file paths |
| Restructure directories/shorten filenames | Manually avoid deep directory nesting or long filenames |
Adhering to best practices, like keeping file paths short and manageable, not only aids in compatibility with various tools and services but also enhances the maintainability and portability of your codebase.

