Git checkouts fail on Windows with "Filename too long error: unable to create file" errors

Still need help?

The Atlassian Community is here for you.

Ask the community

Platform Notice: Server and Data Center Only - This article only applies to Atlassian products on the server and data center platforms.

Summary

When Bamboo checks out changes from repositories using the Windows Git.exe executable, the task fails and the following appears in the job log

java.lang.RuntimeException : com.atlassian.bamboo.plugins.stash.repository.StashRepositoryException: com.atlassian.bamboo.repository.RepositoryException: Checkout to revision <hash> has failed.command 'C:\Program Files\Git\cmd\git.exe' checkout -f master failed with code 1. Working directory was [<job working directory>]., 
stderr: error: unable to create file <filename>: Filename too long error: unable to create file

Cause

According to the msysgit wiki on GitHub and the related fix this error, Filename too long, comes from a Windows API limitation of file paths having 260 characters or fewer.

Solution

To resolve this issue, we could change the Windows default 260 character limit in the Windows registry or by configuring the core.longpaths workaround in git config.

Starting in Windows 10 (Windows Server 2016), version 1607, MAX_PATH limitations have been removed from common Win32 file and directory functions. However, you must opt-in to the new behaviour. We need to set the Windows default 260 character limit by updating the registry as mentioned here

Go to the registry key Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem\LongPathsEnabled (Type: REG_DWORD) must exist and be set to 1.

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


The git configuration setting can be used for Windows versions lower than 2016 and Windows 10.


This setting is disabled by default by git to prevent users from checking out files that Windows Explorer, cmd/bash or some IDE cannot handle.


For Git configuration run the following command from GitBash or the Git CMD prompt:

git config --system core.longpaths true


This will allow file paths of 4096 characters.

Some users have reported the --system parameter does not work, but the --global one does, which would change the command to:

git config --global core.longpaths true

Last modified on Oct 25, 2021

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.