0

I screwed up a local branch on my computer by rebasing it to some other branch. I wanted to rebase but I didn't switch to the branch I wanted to rebase, and as a result I screwed up somebranch. I had no idea how to undo my rebase screwup in somebranch (if anyone knows it would be good to know for the future) so I decided that since I have somebranch on github I would just delete it locally and then pull it from github. I don't know what I did but I screwed that up too. Eventually I found what I believe to be the right commands to recreate a deleted local branch by pulling it in from my remote origin:

git fetch origin somebranch:refs/remotes/somebranch
git checkout -b somebranch --track origin/somebranch


In gitk I can see there are three things now:
somebranch, remotes/somebranch, remotes/origin/somebranch

but all my other branches only show a local and one remote. example:
someotherbranch, remotes/origin/someotherbranch

I ran git for-each-ref and both ref/remotes/somebranch and ref/remotes/origin/somebranch point to the same commit.

My question is what is the difference between the two and how do I get rid of the ref/remotes/somebranch. I tried git update-ref -d remotes/somebranch but it didn't work.

loop
  • 3,460
  • 5
  • 34
  • 57

1 Answers1

1

You almost had it. Just add 'refs':

git update-ref -d refs/remotes/somebranch

You can confirm it's gone by issuing, in the top level of the repository:

ls .git/refs/remotes
Christopher
  • 42,720
  • 11
  • 81
  • 99
  • Thanks a lot that worked. When I run `git remote show origin` I see that it says `Local branch configured for 'git pull': somebranch merges with remote somebranch`. But none of my other branches have an entry for 'git pull'. Is that normal? – loop Jun 19 '12 at 04:28
  • Depends entirely on how you set them up to begin with. If you want to set an "upstream" branch, which will enable `git pull`, this should help: http://stackoverflow.com/a/2286030/877115 – Christopher Jun 19 '12 at 04:54