This is one that’s caught me out on more than one occasion now, hopefully by blogging it I won’t forget about it again quite so soon…
When attempting to push to a git repository over HTTP, you may experience a “broken pipe” error along the lines of the following:
Counting objects: 14466, done. Delta compression using up to 4 threads. Compressing objects: 100% (3746/3746), done. error: RPC failed; result=22, HTTP code = 400 fatal: The remote end hung up unexpectedly Writing objects: 100% (14466/14466), 104.13 MiB | 31.34 MiB/s, done. Total 14466 (delta 10927), reused 13812 (delta 10474) fatal: The remote end hung up unexpectedly fatal: expected ok/error, helper said '2004�Ȍ/↓/Ɠyb��Nj}↑z��"#7‼.m���+x9`>��☼�uhh_������м5���§��z���W?�^&��͙mQM��a`Q�C���Z' fatal: write error: Broken pipe
This error occurs when the amount of data you’re trying to push in one go exceeds git’s http post buffer which is defined in the docs as:
Maximum size in bytes of the buffer used by smart HTTP transports when POSTing data to the remote system. For requests larger than this buffer size, HTTP/1.1 and Transfer-Encoding: chunked is used to avoid creating a massive pack file locally. Default is 1 MiB, which is sufficient for most requests.
Whilst most day to day pushes are likely to be under 1MB, if you’re pushing a large repository over HTTP for the first time, there’s a good chance you’ll exceed this limit, resulting in the above error.
Increasing the buffer is a simple config change to set the new size in bytes (a value which will obviously need to exceed the size of the push that’s erroring):
git config http.postBuffer 209715200
One more thing – even after increasing git’s buffer I was still getting fatal errors. If you also host the destination repository, you need to make sure the server it’s running on doesn’t have a limit to the size of POST requests it will accept – a configuration change may be required to that as well. After I bumped up my max request length, everything worked as expected.