Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

git

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.)

How can I do this?

like image 620
Richard Avatar asked Nov 08 '13 17:11

Richard


People also ask

How do I delete all local commits?

If your excess commits are only visible to you, you can just do git reset --hard origin/<branch_name> to move back to where the origin is. This will reset the state of the repository to the previous commit, and it will discard all local changes.

What does it mean when your branch has diverged?

Follow. Occasionally, you or your team members may run into a diverged branch. A diverged branch means the data you're looking at locally isn't the same as what is currently stored on our servers.


2 Answers

git fetch origin git reset --hard origin/master 
like image 81
SLaks Avatar answered Sep 18 '22 07:09

SLaks


To preserve your old commits on a temporary branch in case you need them:

git branch temp 

Then switch to the new master

git fetch origin git reset --hard origin/master 
like image 35
jdramer Avatar answered Sep 18 '22 07:09

jdramer