Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git: Discard all changes on a diverged local branch

Tags:

git

People also ask

How do I reset a diverged branch?

Sometimes a branch has diverged from origin so much, that it doesn't make sense to try to resolve all the conflicts. In this case, it's better to just reset your local branch to whatever is on origin. To do this, you need to fetch first and then run git reset --hard origin/<branch> .

What is diverged in git?

A branch in git is a series of interrelated commits. If two branches follow a non-linear path then they diverge each other. The diagram shows two diverged branches master and feature.


git checkout phobos
git reset --hard origin/phobos

This tells Git to reset the head of phobos to the same commit as origin/phobos, and to update the working tree to match.


Delete the branch, then re-create it:

$ git branch -D phobos
$ git checkout --track -b phobos origin/phobos