tags:

views:

133

answers:

1

I have a bare repository that's used as the central store for my project. All the developers do "git clone " 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 " 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.dir directory than directly hacking the HEAD file.

thanks Kevin

+9  A: 

If you have access to the remote bare repo, this article suggests:

git symbolic-ref HEAD refs/heads/mybranch

Which will update the HEAD file in your repository so that it contains:

ref: refs/heads/mybranch

as documented in the git-symbolic-ref


If you don't have access to the remote repo, see my previous answer.

VonC
Thanks! I do have direct access to the remote bare repo so git-symbolic-ref will do the job. I like the no-common-ancestor trick mentioned on the other thread, though - definitely one for the bottom drawer.I spent ages Googling for this but couldn't find your previous answer, yet "git remote head master" finds it as the second-highest ranked hit, just below git-remote(1). Bizarre. Just goes to show how hard it is to find something when you don't know exactly what you're looking for.
kbro