I'm trying to change the default branch when cloning from a git bare repo using git 1.8.3.1 from yum install. I had always assumed that the way to do this would be to change the reference inside the HEAD file of the remote repo, and several SO answers seem to confirm this.
However, I'm finding the value of HEAD in the remote bare repo to have no effect. Even though my remote repo has this value in HEAD:
ref: refs/heads/secondbranch
I'm still defaulted to firstbranch branch when I clone! Any ideas what's going on here? Where else might this info be stored?
Old versions of git do not send the "default branch" when fetching and cloning. Instead, they send the object ID of the current HEAD reference, as well as the object ID of the other references. If the object ID of HEAD is the same as the object ID of another reference, it will set HEAD to point to that reference. (If there was no match, you will be in a detached HEAD state.)
The disambiguation logic is fuzzy, though, if you have more than one branch pointing to the same commit. It will prefer a branch named master, then it will simply pick the one it saw first.
Stop laughing, I'm serious.
This was fixed in Git 1.8.4.3.