tags:

views:

180

answers:

2

I have a local topic branch that's tracking a remote branch. For the sake of argument, say the commit histories look like this:

A--B--C--O1--O2--O3 (origin/phobos)
       \
         L1--L2--L3 (phobos)

Having looked at the relative commit histories, I now want to discard all the changes to the local phobos branch and get it back to being a direct copy of origin/phobos, so that the local history looks like this:

A--B--C--O1--O2--O3 (phobos origin/phobos)

I really don't want the local changes to the phobos branch, and I really don't want any merges to show up in the origin repository afterwards. (So, just merging isn't what I have in mind.)

This seems like it should be really easy, but my google-fu has failed me. How do I do this?

+5  A: 

Delete the branch, then re-create it:

$ git branch -D phobos
$ git checkout --track -b phobos origin/phobos
mipadi
Awesome. This worked perfectly.
Electrons_Ahoy
+6  A: 
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.

Dan Moulding
IMO this should be the accepted answer; it issues the "reset" command to transplant the branch pointer, instead of performing surgery with removing/recreating.
vdboor
Actually, I tried this one first and it threw a ton of errors making by local copy nearly unusable. Delete / recreate may have been less elegant, but I didn't have to ask any follow-up questions.
Electrons_Ahoy
@Electrons_Ahoy: Hmm, that's definitely not normal. Doing this reset should normally be a problem-free operation if your repo is in good working order.
Dan Moulding