Failed to push some refs to git server non-fast-forward updates were rejected

Saturday, 27. October 2012

If you have ever come across such errors as this below while pushing your changes to your git server repository..

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

It will be because Git with all it’s wisdom, is trying to save your bits as it has detected there are changes to the repository you are pushing stuff too that could be lost should you continue. This could happen if someone else is accessing and/or trying to update the same branch of the same repository you are trying to update.

To solve such problem you can either

– Fetch and merge the remote repo manually.
– Use “git pull” to both fetch and merge insentiences at once then – git push your changes.
– Finally, you can use the –force flag to tell git to simply overwrite the stuff.

However, the later should be the least recommended approach and only use it if you are the only one using the remote repository or you are sure nothing will actually be lost on that branch.

Enjoy gittin’!

Leave a Reply

You must be logged in to post a comment.