threads / discuss / 38928

Change default branch name (server side) while cloning a repository

Subject: Change default branch name (server side) while cloning a repository

## tl;dr

4 messages between Mar 27, 2015 and Mar 27, 2015.

replies: 3people: 4as markdown or json

Garbageyard· Mar 27, 2015, 12:27 UTC · lore

We use Gitolite for access control and i have admin access on Git server. I wanted to make sure that whenever a new repository is created and is then cloned on any machine, the default branch should point to mainline. To do this, when I run the repository creation script, i change the content of file HEAD of a given repository to point to mainline i.e., default entry of “ref: refs/heads/master” in file HEAD is changed to “ref: refs/heads/mainline”.

For example, if "work" is the repository name, then on Git server,
[gitolite@gitserver  repositories]$ cd work.git/

[gitolite@gitserver work.git]$ cat HEAD ref: refs/heads/mainline

If i now clone the repository on my local machine, then the default branch should be pointing to mainline and not master. However, the issue is that it still points to master. Am I /wrong/ in assuming that changing the entry in file HEAD for a given repository on Git server will change the default branch while cloning? If I’m wrong, can anyone please tell me how can I enforce this change on the /server/ side correctly?

-- View this message in context: http://git.661346.n2.nabble.com/Change-default-branch-name-server-side-while-cloning-a-repository-tp7627964.html Sent from the git mailing list archive at Nabble.com.

Stefan Näwe· Mar 27, 2015, 14:27 UTC · re: Garbageyard · lore

Re: Change default branch name (server side) while cloning a repository

Am 27.03.2015 um 13:27 schrieb Garbageyard:
Show 21 quoted lines
> We use Gitolite for access control and i have admin access on Git server. I
> wanted to make sure that whenever a new repository is created and is then
> cloned on any machine, the default branch should point to mainline. To do
> this, when I run the repository creation script, i change the content of
> file HEAD of a given repository to point to mainline i.e., default entry of
> “ref: refs/heads/master” in file HEAD is changed to “ref:
> refs/heads/mainline”.
> 
> For example, if "work" is the repository name, then on Git server,
> 
> [gitolite@gitserver  repositories]$ cd work.git/
> 
> [gitolite@gitserver  work.git]$ cat HEAD
> ref: refs/heads/mainline
> 
> If i now clone the repository on my local machine, then the default branch
> should be pointing to mainline and not master. However, the issue is that it
> still points to master. Am I /wrong/ in assuming that changing the entry in
> file HEAD for a given repository on Git server will change the default
> branch while cloning? If I’m wrong, can anyone please tell me how can I
> enforce this change on the /server/ side correctly?
Works for me with  "gitolite3 v3.6.2-24-g8e36230 on git 2.3.4".
Could it be that the repo was emtpy when you tried to clone it ?
Stefan
-- 
----------------------------------------------------------------
/dev/random says: Half of the people in the world are below average.
python -c "print '73746566616e2e6e616577654061746c61732d656c656b74726f6e696b2e636f6d'.decode('hex')" 
GPG Key fingerprint = 2DF5 E01B 09C3 7501 BCA9  9666 829B 49C5 9221 27AF
Jeff King· Mar 27, 2015, 16:47 UTC · re: Stefan Näwe · lore

Re: Change default branch name (server side) while cloning a repository

On Fri, Mar 27, 2015 at 03:27:27PM +0100, Stefan Näwe wrote:
Show 8 quoted lines
> > If i now clone the repository on my local machine, then the default branch
> > should be pointing to mainline and not master. However, the issue is that it
> > still points to master. Am I /wrong/ in assuming that changing the entry in
> > file HEAD for a given repository on Git server will change the default
> > branch while cloning? If I’m wrong, can anyone please tell me how can I
> > enforce this change on the /server/ side correctly?
> 
> Works for me with  "gitolite3 v3.6.2-24-g8e36230 on git 2.3.4".
It may be related to the version.

Prior to v1.8.4.3, git servers did not communicate the symbolic ref data to the client. The client guessed it based on which branch had the same sha1 as HEAD, and if there was ambiguity, it guessed "master" over others. So it would usually work, but would sometimes have odd results.

In v1.8.4.3, the server started advertising the name of the branch. You need the client and server both to be that version or more recent for it to work (otherwise, git falls back to the guessing behavior).

-Peff
Matthieu Moy· Mar 27, 2015, 16:40 UTC · re: Garbageyard · lore

Re: Change default branch name (server side) while cloning a repository

Garbageyard <varuag.chhabra@gmail.com> writes:
Show 6 quoted lines
> If i now clone the repository on my local machine, then the default branch
> should be pointing to mainline and not master. However, the issue is that it
> still points to master. Am I /wrong/ in assuming that changing the entry in
> file HEAD for a given repository on Git server will change the default
> branch while cloning? If I’m wrong, can anyone please tell me how can I
> enforce this change on the /server/ side correctly?

IIRC, there's a known limitation of the Git protocol which does not transmit symbolic ref over the network. Only the HEAD's sha1 is transmitted and the client guesses which branch should be checked out based on this. But it can guess incorrectly if several branches point to the same commit.

-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/

← back to recent threads