2

I'm not entirely sure of my process here, not too sure what I did or how it happened. But we've locally deleted the master branch on accident. And now the HEAD of the project has changed to a different branch.

I've tried to run the command-line of:

git remote set-head origin master

But this isn't setting the HEAD back to master, it's just showing a blank line. And if I try to test it with:

git remote show origin

It will return the same query of our new branch being the HEAD.

We have recovered the master branch, I see the master branch now as a regular branch off of my project. But it's no longer accepting all of our changes as HEAD, simply as a seperate branch from the HEAD.

How can I set master branch back to the HEAD of the project? Quite possibly via command-line as we have no access to Settings.

hmijail
  • 1,069
  • 9
  • 17
Andrew Ice
  • 831
  • 4
  • 16

1 Answers1

1

As mentioned in the comments, the most efficient way of doing this is using the RefLog. You can do this:

git update-ref refs/heads/master origin/master
git reset --hard master

This is another question referencing this method.

It sounds like your situation is similar to a detached head.

Community
  • 1
  • 1
U r s u s
  • 6,680
  • 12
  • 50
  • 88
  • Wouldn't this push what belongs to newBranch to master? Because the newBranch is actually an older/outdated branch. – Andrew Ice Sep 01 '15 at 14:09
  • Still not resetting my HEAD sadly...I've tried multiple things from both answers. – Andrew Ice Sep 01 '15 at 15:26
  • @AndrewIce have you tried [VonC](http://superuser.com/users/141/vonc)'s answer in the last link in my answer? – U r s u s Sep 01 '15 at 15:28
  • Yes :( that original one, and the one beneath it. I'm not sure why none of it's working. But it's still leaving the other branch as HEAD. After running git remote show origin: HEAD branch: Am----- – Andrew Ice Sep 01 '15 at 15:37
  • @AndrewIce have you configured an upstream branch for `master`? – U r s u s Sep 01 '15 at 15:44
  • I have upstream set to origin/master – Andrew Ice Sep 01 '15 at 16:11
  • @AndrewIce let's go back to basics. If you do `git checkout master` and then `git remote show origin`, what do you get as HEAD? – U r s u s Sep 02 '15 at 08:44
  • HEAD Ambassador, its one of the older branches we worked on and merged into master. It's like when we accidentally deleted master, it chose another branch to cling to. – Andrew Ice Sep 02 '15 at 13:38