Failed automatic merging - filename too long

Platform Notice: Data Center Only - This article only applies to Atlassian products on the Data Center platform.

Note that this KB was created for the Data Center version of the product. Data Center KBs for non-Data-Center-specific features may also work for Server versions of the product, however they have not been tested. Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.

*Except Fisheye and Crucible

Problem

Merging changesets containing files with long filenames/paths within Bitbucket Server fails.

The following appears in the atlassian-bitbucket.log

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 2016-09-13 15:38:29,640 INFO [http-nio-7990-exec-49] hansberry.nate @XLRZ5Ex938x2166x0 br38av 10.1.2.120 "GET /rest/api/latest/projects/AT/repos/bitbucket_server/pull-requests/110/merge HTTP/1.1" c.a.s.i.s.g.p.DefaultPullRequestAutoMergeStrategy AT/bitbucket_server[5]: Pull request 110@0 failed automatic merging com.atlassian.bitbucket.scm.MergeException: The merge could not be completed automatically. Please clone 'AT/bitbucket_server', checkout 'master' and merge 'feature/awesome_feature' (or commit 'sha1sha1sha1sha1sha1sha1sha1sha1sha1sha1') manually, resolving any conflicts, and push the result. ... Caused by: com.atlassian.bitbucket.scm.CommandFailedException: 'C:\Program Files\Git\bin\git.exe merge -m Automatic merge --no-ff --log sha1sha1sha1sha1sha1sha1sha1sha1sha1sha1' exited with code 128 saying: error: unable to create file really_imagine_that_this_file_name_is_way_too_long_for_Windows_to_handle_because_in_fact_it_should_be_much_longer.txt (Filename too long) error: unable to create file really_imagine_that_this_file_name_is_way_too_long_for_Windows_to_handle_because_in_fact_it_should_be_much_longer.txt (Filename too long) ... Caused by: com.atlassian.utils.process.ProcessException: Non-zero exit code: 128 ...

Cause

Git has a limit of 4096 characters for a filename, but on Windows, when the git client is compiled with Git for Windows (previously compiled with msysGit), it uses an older version of the Windows API and there's a limit of 260 characters for a file path.

Workaround

  1. Ensure the paths to Git\bin\git.exe and Git\cmd have been added to the path variable:

1 2 3 4 5 - Right-Click on My Computer. - Click on Advanced System Settings. - Click on Environment Variables. - Then, under System Variables, look for the path variable and click edit. - Add the path to git's bin and cmd at the end of the string like this: ;C:\Program Files\Git\bin\git.exe;C:\Program Files\Git\cmd.

2. Open PowerShell or cmd.exe and run the following:

1 git config --system core.longpaths true

You should then be able to decline and re-open any pull requests and/or merge as usual.

Updated on April 14, 2025

Still need help?

The Atlassian Community is here for you.