Home > Enterprise >  Cannot change the (remote) default branch (`origin/HEAD`)
Cannot change the (remote) default branch (`origin/HEAD`)

Time:12-05

I wanted to change the remote default branch (origin/HEAD).

So I changed the default branch master to another branch new-default-branch on github. But the origin/HEAD didn't change. I couldn't figure out why it wouldn't update.

So then I deleted master on both local and remote.

Now git rev-parse HEAD returns a commit that I can't see in any history.

What is happening? How do I get origin/HEAD to point to new-default-branch?

CodePudding user response:

I think either you can do it in Settings in GitHub to change the default branch, as mentioned by @Georgios Syngouroglou

or you can run below command in command line to change origin/HEAD to point to any other branch

git remote set-head origin new-default-branch

Regarding your question on how git rev-parse HEAD points to a commit which you can't figure out after deleting the branch,

Branches are just pointers to a commit, so even if you delete a branch, it won't delete your local commit, and the commits will be something like a dangling commit without any reference. HEAD might be still referencing the HEAD commit of master which you deleted and you can see that commit if you do git reflog or git reflog show HEAD

Run git gc to do the garbage cleaning and you can check again if HEAD points to a commit you can't see in History.

CodePudding user response:

Go to your project's GitHub page in the Setting section and then the Branches part. There you could set the default branch in the remote. Change the master value in the picture to new-default-branch. picture of default section in github

  •  Tags:  
  • git
  • Related