I’ve already looked at questions
git rebase and git push: non-fast forward, why use?
and
master branch and 'origin/master' have diverged, how to 'undiverge' branches'?
I’m still not clear on what I need to do in this specific case. I had origin/master and master in sync first. The sequence of commits on both is
---o---A---B
I now commit two more commits on my local repository so that I have
---o---A---B---C---D
Now I did a rebase because I wanted to reorder the commits. So my master is now :-
---o---A---C---D---B
while my origin/master is still as it was in the first situation. Now, if I try to do a git push, it refuses to push it because master and origin/master have diverged. How do I push this rebase to origin?
You can force it with:
Be careful though. This is actually changing the history on origin, so only do this if you know it won’t break anything for other devs, for example.
In general it’s not a good idea to rebase commits that have already been pushed to a remote/central repository.