My friend\'s local master
branch is apparently a disaster (through accidental merge
s and commit
s, I guess). However, his dev branches are
As Jefromi commented,
git checkout master
git reset --hard origin/master
does the right thing: setting the master to its origin state. (If you are already on the master
branch, you can omit the first command.) It also leaves the branch's reflog intact.
Old inferior answer:
git checkout dev
git branch -D master
git checkout master
This switches to another branch ("dev" in this case – choose any other branch you might have), deletes the local master
branch, and then recreates it from remotes/origin/master
(which might not work depending on your settings and Git version). The last command is often equivalent to
git checkout -b master remotes/origin/master
Compared to the new answer above this has the disadvantage that the reflog is destroyed and recreated (i.e. you can't as easy undo this if needed), and it is less clear what happens here. Also, you need to have another branch existing to which you can switch during deletion and recreation (but that was the case in the original question).