Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git non-fast-forward updates were rejected Merge the remote changes

Tags:

git

github

How do I resolve this issue? I am trying to commit but I get the below error.

git push origin monty_svm_dev

To [email protected]:  ! [rejected]        monty_svm_dev -> monty_svm_dev (non-fast-forward) error: failed to push some refs to '[email protected]:/mygit.git' 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. root@li409-202:~/mypath# 
like image 686
Tampa Avatar asked Sep 02 '12 14:09

Tampa


People also ask

How do you fix a non-Fast-Forward rejection?

If you do a commit in one project and then accidentally push this commit, with bypassing code review, to another project, this will fail with the error message 'non-fast forward'. To fix the problem you should check the push specification and verify that you are pushing the commit to the correct project.

What is rejected non-fast-forward?

Git push rejected non-fast-forward means, this error is faced when git cannot commit your changes to the remote repository. This may happen because your commit was lost or if someone else is trying to push to the same branch as you. This is the error you face.

What is non-fast-forward in git?

A non-fast-forward merge is a merge where the main branch had intervening changes between the branch point and the merge back to the main branch. In this case, a user can simulate a fast-forward by rebasing rather than merging. Rebasing works by abandoning some commits and creating new ones.


1 Answers

do git pull origin monty_svm_dev first

What has happened is that the remote has more recent changes than your branch.

So before you can push your changes, you need to get and merge the changes on the remote first.

You can do this either by doing a git checkout your_branch, then:

git fetch origin your_branch and then a
git merge your_branch

or

git pull origin your_branch # fetch and merge in one operation 

Where your branch is master, or your branch name (seems to be monty_svm_dev in your case I think)

Once this is done (and any conflicts resolved) you can do a git push origin monty_svm_dev

like image 71
Michael Durrant Avatar answered Sep 21 '22 23:09

Michael Durrant