539

When I tried to run

git push origin master --force

I just got

Counting objects: 2649, done.
Delta compression uses up to 2 threads.
Compressing objects: 100% (1280/1280), done.
error: RPC failed; result=22, HTTP code = 413 | 116 KiB/s   
fatal: The remote end hung up unexpectedly
Writing objects: 100% (2504/2504), 449.61 MiB | 4.19 MiB/s, done.
Total 2504 (delta 1309), reused 2242 (delta 1216)
fatal: The remote end hung up unexpectedly
Everything up-to-date

Is it something to do with not being secure? I tried creating a public key as the answer for Fatal: The remote end hung up unexpectedly and rerunning it, but it still doesn't work. Am I not actually using the key? If so, how do I use it?

9
  • please show output of git remote -v
    – CharlesB
    Mar 6, 2013 at 6:59
  • 3
    possible duplicate of Git fails when pushing commit to github
    – CharlesB
    Mar 6, 2013 at 7:01
  • 38
    git config http.postBuffer 524288000 # it works for me
    – Hari Das
    Oct 25, 2014 at 14:37
  • 4
    I could not get any of the suggested solutions to work. Then I tried GitKraken. It is one of the few Git programs that doesn't use git.exe. GitKraken could do it. After GitKraken had pushed the repository I could switch back to git.exe and sync without any issues. Feb 26, 2017 at 10:53
  • 1
    it might be due to network issues
    – AmiNadimi
    Jun 6, 2017 at 7:21

54 Answers 54

856

This is due to git/https buffer settings.

Run this (taken from Git fails when pushing commit to github):

git config http.postBuffer 524288000

Then, run your original command again.

17
  • 10
    I need the buffer to be higher than 500MB - is that possible? It doesn't seem to make a difference if I make the postBuffer number any higher...
    – jowie
    Sep 11, 2013 at 13:45
  • 28
    Would it be a good idea to use this with --global? I deal with large repositories regularly.
    – DaAwesomeP
    Feb 2, 2015 at 20:55
  • 5
    @shivam13juna nothing is ever deleted from the internet: :) web.archive.org/web/20170119225336/http://github.com/gitlabhq/…
    – Roman M
    Feb 17, 2019 at 9:06
  • 36
    I ran "git config http.postBuffer 524288000", but still issue not resolved, it still saying the same, the remote end hung up unexpectedly
    – Narendra
    Feb 25, 2020 at 1:38
  • 3
    @jowie I have written an answer attempting to note why this value can be as high as 2000000000 (2 GB), and what else needs to be done to make it work.
    – Asclepius
    Oct 28, 2020 at 2:16
142

Cause: The default file post size for Git has been exceeded.

Solution: Navigate to repo. Run the following command to increase the buffer to 500MB after navigating to the repository:

git config http.postBuffer 524288000
6
  • 61
    You can also use git config ssh.postBuffer 524288000 if posting over ssh instead of http.
    – John M
    May 11, 2015 at 21:01
  • 9
    For some cases git config --global http.postBuffer 100000000
    – Job M
    Nov 11, 2019 at 13:23
  • I get 'fatal: not in a git directory' after execution of this command
    – ka3ak
    Feb 5, 2020 at 13:44
  • 3
    @JohnM This option doesn't seem to exist, it's not documented in the man page or git-scm.com/docs/git-config
    – Nobody
    Feb 10, 2020 at 11:58
  • I have written an answer attempting to note why the http.postBuffer value can possibly be as high as 2000000000 (2 GB), and what else needs to be done to make the push succeed.
    – Asclepius
    Oct 28, 2020 at 2:29
121

This looks similar to How do I get github to default to ssh and not https for new repositories. Probably it's worth trying to switch from http protocol to ssh:

$ git remote add origin [email protected]:username/project.git
12
  • Why can't I just switch from http to https?
    – DanielLC
    Mar 7, 2013 at 2:58
  • 16
    bash-3.2$ git remote add origin [email protected]:xxx/xx.git fatal: remote origin already exists. WHY ?
    – almaruf
    Nov 3, 2014 at 10:36
  • 18
    @almaruf it is because the remote origin is already there and you are trying to replace it. git doesn't allow that. So you have to first do git remote rm origin then try again. It would work
    – Alfie
    Apr 25, 2015 at 11:28
  • 2
    make sure you initialise the project if it's a new fresh clone with git init
    – Raul
    Jul 21, 2016 at 9:29
  • 22
    Could someone explain WHY this would be the solution? As a less experienced github user, this question and the one linked in the answer don't appear to have any connection. I'm hesitant to learn how to do this when there is no logical explanation of why switching to SSH would solve the problem of "remote end hung up unexpectedly" Oct 15, 2020 at 13:44
60

You might get an error like this

error: could not lock config file .git/config: No such file or directory

that is because you don't have a local .git/config file You can get it working by this command:

git config --global http.postBuffer 524288000
2
  • 3
    this helped me when trying to clone on a very slow PC inside cygwin - it continued to remote end hung up - until I used this command
    – serup
    Apr 5, 2017 at 21:52
  • This help me to resolve the "fatal: The remote end hung up upon initial contact" issue.
    – Karthic.K
    Jun 5, 2017 at 4:53
57

Culprit (in my case):
A high-latency network.

This is not an answer per se but more of an observation that may help others. I found that this error pops up occasionally on high-latency networks (I have to use a Satellite dish for internet access for example). The speed of the network is fine, but the latency can be high. Note: The problem only exists in certain scenarios, but I have not determined what the pattern is.

Temporary mitigation:
I switched networks—I moved to a slower, but lower latency cell network (my phone used as a hotspot)—and the problem disappeared. Note that I can only do this itermittently because my cell connectivity is also intermittent. Plus the bandwidth usage adds costs. I'm also lucky that I have this option available to me. Not everyone does.

I'm sure there is some configuration setting somewhere that makes git—or ssh or curl or whatever times out first—more tolerant of such networks, but I don't know what it is.

A plea to developers:
These kinds of issues are a constant problem for rural populations. Please think of us when you design your systems, tools, and applications. Thank you.

2
  • ssh itself has some tuning options (keepalives etc) but the main tuning options are generally kernel-level and need to be set on both sides (e.g., over on GitHub as well). Kind of a problem. Something I'd like to see for cases like yours is an aggregator (LAGG interface style) that can use both the satellite and the cell phone networks. This is unfortunately far from trivial.
    – torek
    Nov 18, 2021 at 7:12
  • I used "Network link conditioner" from Xcode's additional tools and applied "3G" profile from my mac machine. I worked :) Jul 14, 2022 at 14:40
48

Other solutions didn't work in my case, doing a garbage collection fixed it for me:

git gc --aggressive

You can try with just git gc first.

4
  • 42
    This fixed my problem, but it also squashed the detached HEAD changes into a state where merging them became obnoxious (everything was converted to an ADD). I wish I had researched this one more before running it. Jul 1, 2016 at 3:40
  • This fixed my problem. My problem was (using ssh): $ git push | Enumerating objects: 886, done. | Counting objects: 100% (850/850), done. | Connection to bitbucket.org closed by remote host. | fatal: the remote end hung up unexpectedly | Compressing objects: 100% (831/831), done. | fatal: the remote end hung up unexpectedly
    – manuelpgs
    Sep 9, 2020 at 2:58
  • Git will exec gc command automaticly before exec push command
    – linjiejun
    Sep 21, 2020 at 8:45
  • @linjiejun in my case, I could not push until I pulled first, and the pull is where I was getting the error "fatal: Out of memory, malloc failed..."
    – brethvoice
    Jul 13, 2021 at 15:36
25

Contrary to one of the other answers - I had the problem on push using ssh - I switched to https and it was fixed.

git remote remove origin
git remote add origin https://github.com/user/repo
git push --set-upstream origin master
2
  • 1
    One can use git remote set-url origin https://github.com/user/repo. No need to remove first Aug 5, 2021 at 12:35
  • not solve the error Dec 29, 2022 at 22:55
22

If using GitHub, in the repo's directory, run this command to set http.postBuffer to what appears to be its maximum allowable value for GitHub:

git config http.postBuffer 2147483648

If cloning a repo instead using git clone, it can be cloned with the same option:

git clone -c http.postBuffer=2147483648 [email protected]:myuser/myrepo.git /path/to/myrepo

In both cases, the number above is equivalent to 2 GiB. It is however possible that you will need up to this amount of free memory to be able to use this value.

Ensure that each push to GitHub has commits that don't add more than this size of changes. In fact I would keep the commit push size under 1.8 GiB to be safe. This can require dividing a large commit into smaller commits and pushes.

Why this value?

This specific value is used because at least as of the year 2018, this value was documented (archive link) as the push size limit of GitHub:

we don’t allow pushes over 2GB

Why not set lower?

Some prior answers say to set it to 524288000 (500 MiB), but this number seems arbitrary and without merit. Any lower value should work as long as your push size is not larger than the set value.

Why not set higher?

If instead you set the value to higher than 2 GiB, and if your attempted push size is also higher, you can expect the documented error with GitHub:

remote: fatal: pack exceeds maximum allowed size

15

The following commands might help you...

git config --global http.postBuffer 1048576000
git config --global http.lowSpeedLimit 0
git config --global http.lowSpeedTime 999999
1
  • 1
    Setting up http.lowSpeedLimit and http.lowSpeedTime solve my problem. thanks
    – golu_kumar
    Sep 5, 2022 at 12:02
12

Based on the protocol you are using to push to your repo

HTTP

git config --global http.postBuffer 157286400

References:

SSH

Add the following in ~/.ssh/config file in your linux machine

Host your-gitlab-server.com
  ServerAliveInterval 60
  ServerAliveCountMax 5
  IPQoS throughput

References:

3
  • In this answer, http.postBuffer is effectively set to 150 MiB. If necessary, one can go higher up to 2 GB as I try to explain in my answer.
    – Asclepius
    Oct 28, 2020 at 2:22
  • SSH config just fixed my problem with gitlab.com. Thank you a lot.
    – Alberto
    Jan 23, 2021 at 20:49
  • How do I do this for GitHub? Is my host github.com?
    – Giovanni
    May 9, 2021 at 8:41
10

This error can also be thrown through missing write permissions on the repository.


My concrete case went like this:

  1. I created a repo with the root user of my server (via SSH).
  2. I installed a git service and created a git linux user that should manage all git-related action.
  3. By that time, I had forgotten that the repo was created with the root user in the first place, and the git user simply didn't have the file permissions to write anything into the repository.
9

This article have very good explanation and it solved my problem.

git config --global http.postBuffer 157286400

https://confluence.atlassian.com/stashkb/git-push-fails-fatal-the-remote-end-hung-up-unexpectedly-282988530.html

7

None of the above solutions worked for me, however the commit I was pushing was very large.

Very simply, I split it into two commits and pushed each one separately and it went through instantly.

2
  • can you explain how to split the commit?
    – arilwan
    Feb 22, 2022 at 19:07
  • 1
    @arilwan In my case, there were 5 or 10 files, if I recall correctly, so I committed the first half and pushed it, then committed the second half and pushed that. It went through instantly both times. Feb 23, 2022 at 2:40
6

In my case I got this error, when pushing with Intellij Idea.

Here is how I traced down my error and fixed it.

  • enable debug logging within the terminal, which is never a bad idea :)
set GIT_CURL_VERBOSE=1 set GIT_TRACE=1 
  • push via the terminal, not via intellij
git push 
-> fatal: The current branch feature/my-new-feature has no upstream branch.
To push the current branch and set the remote as upstream

Solution was to set the upstream, which must have been gone wrong before:

git push --set-upstream origin feature/my-new-feature
1
  • This worked for me too, when nothing else would. Thanks, @Lama! Jul 19 at 19:45
6

Even after configuring post buffer the issue was not resolved.

My problem was solved when I changed my wifi network from broadband to my mobile hotspot. This might not be the logically correct answer but it solved the issue.

Make sure you have good internet speed.

1
  • 1
    Thanks for the note. I'm facing the same issue. It seems that something (firewall?) on the local (wifi) network might somehow break the connection to git servers. The connection is otherwise really good here, so I suspect it might be configuration issue on the (MikroTik) router.
    – kub1x
    Apr 9, 2021 at 12:55
5

In our case, the problem was a clone that wrote a .git/config file which contained a url entry that was a read only access method. Changing the url from the :// method to the @ method fixed the problem.

Running git remote -v illuminated the issue some.

5

None of the above answers worked for me, but here's what did.

  1. delete .git/ from your project
  2. clone the remote repo to some new location like your desktop:
    git clone https://github.com/foo/bar.git
    
  3. move .git/ from the new location into the old location
  4. re-commit and push your changes
0
4

If you are using git for windows (and you likely are, if you are doing this on a windows machine), and none of the other fixes here worked for you, try going to https://github.com/git-for-windows/git/releases, and getting a version on or after version 2.4.5. Fixed it right up for me.

1
  • This fixed it for me. I was on 2.41.0.3 and updated to 2.42.0.2 and now its working again! Nov 20 at 16:07
4

Another addition, since I encountered this error a different way and Google took me here.

My problem was a mismatch of case; one camelCase and one not. Apparently, GIT stops you doing this without telling you why. So if your branches are different from the remote only in the capitalization, try changing them to be identical.

See: Git: 'Master cannot be resolved to branch' after merge

1
  • I thought I included all relevant info - it's caused by a case mismatch. I've added a sentence to be more explicit, but this isn't really about the link. Sorry if that wasn't clear.
    – Thomas
    Dec 3, 2015 at 11:08
4

I solved this issue by repacking:

git repack --max-pack-size=100M -a -d

Go to Repository > Open in command prompt in GitHub Desktop Run the following commands:

set GIT_TRACE=1
set GIT_CURL_VERBOSE=1
git push origin <branch>
3

You probably did clone the repository within an existing one, to solve the problem can simply clone of the repository in another directory and replicate the changes to this new directory and then run the push.

1
  • we have a beta ansible workflow and rebuilding the site caused exactly this, cloning the repo on top of the other one. Ansible thing to fix but casing a git problem. Thanks :-) Mar 24, 2016 at 10:33
3

Recently I faced the same problem. When cloning a remote repository I got the error as follows:

fatal: the remote end hung up unexpectedly MiB | 7.00 KiB/s
fatal: early EOF
index-pack failed

When I googled the error I was redirected here. And I followed most of the answers but not solved my problem.

The only solution was to re-install my 'Network adapter (WiFi) driver software'. So, what I want to emphasize is the above error can result from the issues in your PC's WiFi driver software, too. If non of the mentioned answers are not working then you can try reinstalling the WiFi driver. It will solve the issue.

You can easily reinstall the WiFi driver as follows:

  1. Open network and internet settings
    Network and internet settings

  2. Select 'Network reset'
    reset network settings

  3. Then select 'Reset now'
    reset network

After rebooting your pc, try git operations successfully (pushing/pulling/cloning).

2

This may occur after updating your OSX platform.

Open Terminal and navigate to your .ssh-folder, and enter ssh-add -K ~/.ssh/id_rsa

2

PLESK Nginx and GIT I was getting this error on plesk git and while pushing a large repo with (who knows what) it gave me this error with HTTP code 413 and i looked into following Server was Plesk and it had nginx running as well as apache2 so i looked into logs and found the error in nginx logs

Followed this link to allow plesk to rebuild configuration with larger file upload.

I skipped the php part for git

After that git push worked without any errors.

2

For us the problem was that we had a ton of files that should have instead been managed by git lfs.

We did the following to resolve the problem:

# Soft reset so you can author a new commit
git reset --soft HEAD~1

# Install git lfs
git lfs install

# Track large files of a specified file type YMMV
git lfs track "*.uasset" "*.umap"

# Re-add everything
git add .

# Author a new commit
git commit -m "git lfs ftw"

# Push
git push
2

I got the same issue in my project. When I updated my cocoapods library project file size got increased. After a lot of R&D I got the solution from this question but solution does not worked properly.

My Solutions:-

Step 1. Increase your Buffer size first. buffer size you can increase or decrease according to your requirements.

git config http.postBuffer 2147483648

Or

git config http.postBuffer 524288000

Step 2. Run your command to push code

git push origin yourBranchName

Step 3. Check your git repo at Github or Gitlab updated or not. If it is not updated there use this command to force push to git.

git push origin yourBranchName -f

I hope this would resolve your issue.

1

I happened to have the same error at pull.
I have done the "http.postBuffer" trick. It solved it, but when I wanted to push, I encountered the error again.

What solved my problem:
1. Cloned it to an other folder with an other virtual machine. (Linux).
2. I've done my changes.
3. Pushed it with the original virtual machine where I initially couldn't push. (Windows)

1
  • 3
    I know this is not an ideal solution, but it solved the problem in my case. It can be still lifesaver when all the other answer fails, as they did in my case.
    – nopara73
    Jul 11, 2016 at 6:13
1

I have the same problem. I noticed from the git web page that the SSH clone URL have the next structure:

[email protected]:user/project.git

I could resolve my problem just changing the ":" by "/", as follows:

[email protected]/user/project.git

may be this can be helpful.

1

Seems like it can be one of a thousand things.

For me, I was initially pushing master and develop (master had no changes) via SourceTree. Changing this to develop only worked.

1

I was facing a similar error uploading a large repo, "fatal: The remote end hung up unexpectedly" without any further details.

After a lot of research, here's what I did:

  • Using SSH instead of HTTPS, didn't solve the problem.
  • Increasing http.postBuffer incrementally up to a very large value, still no luck.
  • I figured out that it might be because of large files in the repo (as this is a newly migrated repo from perforce), so I recreated the repo using LFS, setting largeFileThreshold to 40m, which greatly reduced the repo size (from 3.5G to 500M). I thought this will solve the problem, but to my surprise I still faced the same error.

Finally, it occurred to me that may be I'm using an older git client, as I didn't see additional error messages. I upgraded git client to latest (2.20.1), and voila, the error is gone!

4
  • I also had this exact issue (migrating from TFS though). I upgraded from 2.19 to 2.20 and it was fixed, a cursory look through release notes didn't reveal what the issue might have been though. Jan 18, 2019 at 9:04
  • I have just upgraded to 2.20.1.windows.1 and it still won't let me push to the remote repository
    – Vidar
    Feb 6, 2019 at 17:43
  • @Vidar May be check for large files, GitHub has a strict limit of 100MB help.github.com/articles/what-is-my-disk-quota; Have a look at "Manually reviewing large files in your repository" section in confluence.atlassian.com/bitbucket/…; the page itself is a good read. Feb 12, 2019 at 22:21
  • @MahmoudHanafy - thanks - it was a parameter in the web.config about max file size - increase that and git behaves and everyone is happy! It's not GitHub for me but our own private on site Bonobo.Git.Server.
    – Vidar
    Feb 13, 2019 at 18:04

Not the answer you're looking for? Browse other questions tagged or ask your own question.