Home·Error messages

git · Git

The message

error: failed to push some refs to 'https://github.com/user/repo.git'

What it means

The server rejected your push, and this line is only the summary — the real reason sits in the ! [rejected] line just above it. Usually the remote has commits you do not, but a protected branch, a server-side hook or a file-size limit produce the same summary. Read the reason first; for the ordinary case git pull --rebase && git push finishes it. The dangerous move is adding --force without reading, because that can erase a colleague's commits from the server.

The fix

git pull --rebase && git push
Printed by
git
Git
29

Almost every git error is a refusal that means "doing that from this state would lose something"; fatal: means git stopped without changing anything, and the hint: lines under the first line usually carry the actual remedy.

Reading an error message

  • Read from the first line down. The lower you go the more it is about the tool’s internals; the cause is usually at the top.
  • If there is a file and a line number, start there — not the top stack frame, but the topmost line that names a file you wrote.
  • Search the message verbatim, but strip your own paths and variable names first; those are what stop the search from matching.
  • The same condition is worded differently across tool versions. If results look wrong, add the version number to the query.
  • Before pasting a fix, check what it throws away. Some of these cannot be undone.

Common questions

Q. What does “error: failed to push some refs to 'https://github.com/user/repo.git'” mean?

The server rejected your push, and this line is only the summary — the real reason sits in the ! [rejected] line just above it. Usually the remote has commits you do not, but a protected branch, a server-side hook or a file-size limit produce the same summary. Read the reason first; for the ordinary case git pull --rebase && git push finishes it. The dangerous move is adding --force without reading, because that can erase a colleague's commits from the server.

Q. How do I fix it?

git pull --rebase && git push — before running it, check the explanation above for what this command discards.

Q. Which tool prints this?

git. It sits under Git, and the message runs to 8 words.

Errors nearby