Andrew Ice
Andrew Ice

Reputation: 841

Deleted a Git Branch and it changed my HEAD, How do I change it back?

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.

Upvotes: 2

Views: 77

Answers (1)

U r s u s
U r s u s

Reputation: 6968

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.

Upvotes: 1

Related Questions