Git: How to revert my local branch to the remote branch state?

you can reset with

git reset --hard HEAD

you will lose all your changes if you do this. This might be helpful.


If you are not afraid of losing any local history, you can switch to another branch then delete your local branch, then check the remote version out. For example, if you wanted to revert a branch called "test_feature," you could do this:

$ git checkout master
$ git branch -D test_feature # see note about -D below
$ git checkout test_feature  # should track origin/test_feature

NOTE: -D will force delete the branch, and will suppress warnings about unmerged changes.

This is useful if you have merged a branch you didn't intend to, as the HEAD pointer can change depending on the type of merge.

EDIT: Another method for doing the same thing is to simply type:

git reset --hard origin/test_feature

This will reset the branch you are currently on to the state of the remote (origin in this case) branch test_feature.

@hvgotcodes has a variation of this in his example (he's targeting the HEAD commit)

Tags:

Git