453

When I try to push to master branch that is hosted on https://github.com I get:

remote: fatal error in commit_refs

How can I solve this?

7
  • Where is the remote repository hosting/located? Might be that this is corrupt? Commented May 20, 2016 at 8:51
  • Thank you for helping! The remote is github. Seems it was a local error (none of the others working against the same repo have had this issue). Commented May 20, 2016 at 13:21
  • This seems to be a recent GitHub issue, see also pastebin.com/50BL9YTF and blastedbio.blogspot.co.uk/2016/05/… also from 20 May 2016.
    – Peter Cock
    Commented May 23, 2016 at 13:39
  • 63
    This can also occur if GitHub has a service outage
    – bendman
    Commented Jun 5, 2017 at 20:04
  • 2
    None of the above solved my issue. However, a good old system restart did. Commented Sep 25, 2017 at 21:44

9 Answers 9

1069

In my case, GitHub was down by the time I was trying to push.

Just check https://www.githubstatus.com to know about GitHub site status.

When it's up you'll be able to push.

3
  • 4
    I waited 10 minutes while githubstatus.com was reporting OK status
    – mirelon
    Commented Mar 27, 2023 at 12:34
  • 1
    Waiting worked for me, even though everything was shown as online
    – Cyrill
    Commented Mar 27, 2023 at 13:55
  • I went to githubstatus.com, read "All Systems Operational", and then assumed that wasn't it. 15 minutes later, githubstatus.com showed that GitHub was down. Commented May 17, 2023 at 4:58
159

This fixed it for me:

git gc

That will start a garbage collection that resolved my error.

3
  • 51
    git gc didn't solve it for me, but git fsck and then git gc did it.
    – dchest
    Commented Jun 2, 2017 at 14:24
  • 5
    docs: git fsck and git gc
    – djvg
    Commented Dec 1, 2021 at 8:28
  • This worked for me also. Good to do some preventative maintenance on a regular basis. Commented May 4, 2023 at 16:58
16

Make sure your repo is online.

I got this error today when attempting to push to github and then couldn't even browse the site without getting their unicorn error message.

5

Try rebase the current branch on top of the upstream branch after pull, e.g.

git pull origin master -r

then push it again:

git push origin master
1
  • 1
    Lol i tried that earlier today, and my repository got absolutely empty cuz it didn't want to push it back, luckily I have all my files saved in my code editor and in backup, but yeah apparently github's down... Commented Aug 10, 2021 at 15:48
4

I raised this with GitHub in relation to http://blastedbio.blogspot.co.uk/2016/05/sync-github-mirror-with-cron.html and it turned out to be due to protected branch settings. GitHub have improved the error message:

$ git push mirror master
Counting objects: 391, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (391/391), done.
Writing objects: 100% (391/391), 99.28 KiB | 0 bytes/s, done.
Total 391 (delta 298), reused 0 (delta 0)
remote: error: GH006: Protected branch update failed for refs/heads/master.
remote: error: You're not authorized to push to this branch. Visit https://help.github.com/articles/about-protected-branches/ for more information.
To [email protected]:HuttonICS/biopython.git
 ! [remote rejected] master -> master (protected branch hook declined)
error: failed to push some refs to '[email protected]:HuttonICS/biopython.git'

If you try again now you ought to get a more constructive error report. In my case I needed to adjust my protected branch settings as per https://help.github.com/articles/about-protected-branches/

1
  • In my case the problem was also caused by protected branch settings.
    – Mouse
    Commented Nov 1, 2016 at 3:50
4

Opening a new terminal and trying worked for me.

1
  • 3
    May have just been lucky and done this as github went back up.
    – Smern
    Commented Aug 10, 2021 at 18:17
3

From my experience, there is now (2019) some rate limit on GitHub that causes this problem for me when mass-pushing tens of huge repositories. It can also cause "cannot read" problem in random cases.

When I delay for 30 seconds before each push, both problems go away and I can continue with hundreds of repos without a glitch (sigh, don't even ask).

0
0

In my case I suspect a hung git process was causing the problem; I killed it and retried and the problem went away.

1
  • This was the most similar to my issue - I just needed to close VSCode, which likely had a git process working in the background that was hung for some reason.
    – Pro Q
    Commented May 4, 2023 at 16:06
-3

Pulling down latest code from the branch solved it for me:

git pull origin master
git push origin master
0

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