Sunday, February 11, 2018

git: Your branch and 'origin/master' have diverged - how to throw away local commits

I have the following message in git:

# Your branch and 'origin/master' have diverged,
# and have 3 and 8 different commits each, respectively.
# (use "git pull" to merge the remote branch into yours)
I would like to throw away the 3 local commits, and pull the 8 remote commits at origin/master.

(Merging is going to be too difficult, I'd rather make the 3 local commits again once master is up to date.)
To erase your latest local commit use the following:

git fetch origin
git reset --hard origin/master

You will get following message:
HEAD is now at 76b2d560 .......................