I was using the following procedure for a while:
git fetch origin master
git merge origin/master
git push --dry-run origin master
git push origin master
Now this has stopped working and produces this error
To git@example.com:company/project/admin.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'git@example.com:company/project/admin.git'
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.
and now only git pull works and not fetch and merge.
Why would this happen? It is also happening to other developers.
I think the problem here is that you’re doing:
… which updates
FETCH_HEADwithmasterfromorigin, but doesn’t update the remote-tracking branchorigin/master.You probably want to do:
… instead, which will update all remote-tracking branches from
origin, includingorigin/master.This is explained in the documentation for
git fetch, but I think it’s fair to say that this is confusing for a lot of people…