Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top
  git commit --amend --allow-empty


  git push origin master

the git said that

! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'remoteurl'
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes (e.g. 'git pull') before pushing again.  See the
'Note about fast-forwards' section of 'git push --help' for details.

Why? How to fix this?

share|improve this question
up vote 46 down vote accepted

The issue is not that you are pushing an empty commit.
It is about pushing a different commit (one with a different SHA1) than the one commit already pushed.
That is what git commit --amend does: it modified the last commit, it doesn't create a new one.

That means you are pushing a different history than the one others might have already cloned.
If you are sure that won't be a problem, you need to force the push:

git push -f origin master

Should you have done:

git commit --allow-empty

You would have created a new (empty) commit, which you could have pushed without any issue.

share|improve this answer

If you want to create pull request on Github. You can:

git commit --allow-empty -m "make pull request"

Then create pull request with no change.

share|improve this answer

Make sure the remote branch you are trying to push to isn't currently checked out. I made a git repository on one of my servers once and couldn't figure out why I couldn't push to it. After a day or so of troubleshooting, I found out that I couldn't push to the repository (or the branch I wanted to) while it was checked out on the server repository. So, I simply made a new branch that I checkout when I'm done making changes on the server, and I can then push to the server. This might not be your issue, but I was getting an error similar to this when I had an issue pushing to an empty git on my server.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .