What do I do if a colleague has rebased after pushing?

Viewed 109

I had checked out somebranch. A colleague has done some work and rebased it, now origin/somebranch is parallel to somebranch. I've done no work on the branch, but I am 14 commits behind, 3 commits ahead and with merge conflicts on two files. What do I do to not add a junk merge now?

Bonus question: what should I do if I had done some local work on the pre-overwrite branch?

EDIT:

To clarify what I've done. I did

git fetch
git checkout somebranch

Some time later I clicked on the sync button in vscode which, as far as I know, does attempt

git pull origin somebranch
git push origin somebranch

The operation failed, there has been a merge initiated on two files.

The histories now look like (a longer version of) this:

* 8e1e0ed - (2 days ago) commit9 (origin/somebranch)
* c87977f - (9 days ago) commit8
* adfc49e - (3 weeks ago) commit2
* 7c8e72e - (3 weeks ago) commit1
* e158c80 - (8 days ago) commit7 (origin/master, master)
* 2357f78 - (8 days ago) commit6
| * 7b507a3 - (9 days ago) commit5 (HEAD -> somebranch)
| * 2a7af7b - (3 weeks ago) commit2
| * c424261 - (3 weeks ago) commit1
|/  
* 48098a0 - (3 weeks ago) commit0

I.e. commit1 and commit2 are different on my version of branch and origin. And commit5 is replaced with other commits. What am I supposed to do now?

1 Answers

Keeping commit 5

Commit 1 and 2 already exist, so the only commit to rebase is commit 5, and HEAD is at the end of your branch with commit 5 so that doesn’t need specifying.

git rebase --onto origin/somebranch HEAD~

A new commit 5 will be created with a parent of commit 9.

Not keeping commit 5

If you don’t want any of the commits on your branch, that’s a simpler situation. It’s just a case of resetting your local branch to the remote branch.

git reset --hard origin/somebranch
Related