I'm using Git to manage my two computers and my development. I'm trying to commit changes to GitHub and I'm getting the error.
Failed to push some refs to
<repo>
. To prevent you from losing history, non-fast-forward updates were rejected. Merge remote changes before pushing again.
What could be causing this and how can I fix this?
EDIT:
Pulling the repo returns the following:
*branch master->master (non-fast-forward) Already-up-to-date
Pushing still gives me the aforementioned error.
You need to merge and resolve the
conflicts locally
before you push your changes to remote repo/fork.1) pull (fetch and merge)
2) Push the changes
Still you have a quick choice to
push
forcibly by using--force
option but should be avoided as it may result in changes loss or affect badly on other contributors.GitHub has a nice section called "Dealing with “non-fast-forward” errors"
Git cannot make changes on the remote like a fast-forward merge, which a Visual Git Reference illustrates like:
This is not exactly your case, but helps to see what "fast-forward" is (where the
HEAD
of a branch is simply moved to a new more recent commit).The "
branch master->master (non-fast-forward) Already-up-to-date
" is usually for local branches which don't track their remote counter-part.See for instance this SO question "git pull says up-to-date but git push rejects non-fast forward".
Or the two branches are connected, but in disagreement with their respective history:
See "Never-ending GIT story - what am I doing wrong here?"
Never do a git -f to do push as it can result in later disastrous consequences.
You just need to do a git pull of your local branch.
Ex:- git pull origin 'your_local_branch'
and then do a git push
It means that there have been other commits pushed to the remote repository that differ from your commits. You can usually solve this with a
before you push
Ultimately, "fast-forward" means that the commits can be applied directly on top of the working tree without requiring a merge.
you might want to use force with push operation in this case
git push origin master --force
A fast-forward update is where the only changes one one side are after the most recent commit on the other side, so there doesn't need to be any merging. This is saying that you need to merge your changes before you can push.