Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

git

I messed my local branch of a project, and i want to revert my local copy to the remote state. How i acomplish that simply goal?

like image 675
LuisEspinoza Avatar asked Mar 21 '12 19:03

LuisEspinoza


2 Answers

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)

like image 183
zedd45 Avatar answered Oct 10 '22 05:10

zedd45


you can reset with

git reset --hard HEAD

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

like image 33
hvgotcodes Avatar answered Oct 10 '22 06:10

hvgotcodes