Fixing a Stuck Git Push (That Hangs)

Tim Mouskhelichvili
Tim Mouskhelichvili
3 minutes to read

When pushing a commit to a Git hosting service like Github, Gitlab, or Bitbucket, some developers experience a stuck push. The command hangs, and nothing happens.

Here are some of the reasons why this behavior can happen:

  1. Your GIT credentials are invalid.
  2. There is an issue with your ssh-agent.
  3. The remote you are trying to push to is invalid.

This article explores different reasons for this behavior and proposes multiple solutions for fixing the git push command.

Let's get to it 😎.

git push stuck

Since this behavior can happen for many different reasons, you will need some debugging skills to find the REAL reason.

Go down this list of reasons and eliminate them one by one until you find the culprit.

Reason #1 - The remote URL is invalid

First of all, you need to verify that you are pushing to the correct remote URL.

Here is how you can show a remote URL:

bashgit remote show <remote>

Here is how you can replace a remote URL:

bashgit remote set-url origin git@github.com:username/myrepo.git

P.S. On GitHub for example, HTTPS may not work and you might need to use SSH.

Reason #2 - Issue with the ssh-agent

An additional possible reason your git push command hangs is there may be something wrong with the ssh-agent.

To fix this issue, restart the ssh-agent, like so:

bashkillall ssh-agent; eval `ssh-agent`

The best Web Development course in 2023! 👉 Learn Web Development

Reason #3 - Invalid credentials

A further possible reason your git push is stuck is that the credentials used to access your Git hosting service (Gihub, Gitlab, Bitbucket, etc.) are invalid or out-of-date.

To fix this issue, you need to re-login to your Git hosting service through Git, like so:

bashgit config --global core.askpass "git-gui--askpass"

Reason #4 - You are trying to push a very large file

One more possible reason your git push hangs is that you are trying to push a very large file.

You may need to increase the Git post buffer size to fix this issue.

Here is how you can increase it locally:

bashgit config --local http.postBuffer 524288000

You can also increase the Git buffer size for every Git repository on your system like so:

bashgit config --global http.postBuffer 524288000

Reason #5 - VPN proxy issue

An extra possible reason your git push hangs is your VPN has an issue.

Here is how you can debug a VPN proxy issue:

bashGIT_CURL_VERBOSE=1 GIT_TRACE=1 git push

Try restarting your VPN to fix this issue.

Reason #6 - Garbage collector issue

Another possible reason you git push hangs is you have an issue with the garbage collector.

To fix this issue recalculate the deltas of your Git repository.

Here is how you do it:

bashgit gc

Final thoughts

If no solutions from that list work for you, you may need to reinstall Git on your system.

git push stuck

Here are some other Git tutorials for you to enjoy:

The best Web Development course in 2023! 👉 Learn Web Development

Comments (1)
Reply to:
Thato October 23, 2023 22:09PM
Thank you Tim, very helpful indeed.
REPLY