I have a bare repository that’s used as the central store for my project. All the developers do git clone <repo> to share with it. When they do the clone, they get a checkout of the master branch (unless they do git clone -n) because repo.git/HEAD contains ref: refs/heads/master, making this the Active Branch.
The question is, how do I change the Active Branch properly? I could simply hack the repo.git/HEAD file directly, but that seems nasty and, well, hacky.
I tried doing git checkout <otherbranch> in the repo .git directory, but that failed because I wasn’t in a work tree.
I tried git update-ref HEAD refs/heads/otherbranch but that just updated refs/heads/master to be the same as refs/heads/otherbranch (okay, I did that one in a dummy repository, not my production one!)
I tried git update-ref --no-deref HEAD refs/heads/otherbranch and that almost worked. It updated the HEAD file, but it set it to the SHA1 of the commit pointed to by refs/heads/otherbranch.
I’m testing with git version 1.7.0.2.msysgit.0.
I’m guessing there’s no way to do this through git push, as allowing all and sundry to change your default branch seems a bit unsafe (!), but surely there’s a better way to do it in the repo .git directory than directly hacking the HEAD file.
If you have access to the remote bare repo, this article suggests:
as documented in the
git-symbolic-refIf you don’t have access to the remote repo, see my previous answer.
Remember that a command like
git remote set-head:doesn’t change the default branch of the remote repo.
It only changes a remote tracking branch stored in your local repo as
refs/remotes/<name>/HEADdoesn’t change
HEADitself (again, onlyrefs/remotes/<name>/HEAD), hence the need forgit symbolic-ref.So
git remote set-headis not the answer here.git symbolic-ref HEADis, if you have direct access to the remote repo.