git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* Change default branch name (server side) while cloning a repository
@ 2015-03-27 12:27 Garbageyard
  2015-03-27 14:27 ` Stefan Näwe
  2015-03-27 16:40 ` Matthieu Moy
  0 siblings, 2 replies; 5+ messages in thread
From: Garbageyard @ 2015-03-27 12:27 UTC (permalink / raw)
  To: git

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.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Change default branch name (server side) while cloning a repository
  2015-03-27 12:27 Garbageyard
@ 2015-03-27 14:27 ` Stefan Näwe
  2015-03-27 16:47   ` Jeff King
  2015-03-27 16:40 ` Matthieu Moy
  1 sibling, 1 reply; 5+ messages in thread
From: Stefan Näwe @ 2015-03-27 14:27 UTC (permalink / raw)
  To: Garbageyard, git@vger.kernel.org

Am 27.03.2015 um 13:27 schrieb Garbageyard:
> 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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Change default branch name (server side) while cloning a repository
  2015-03-27 12:27 Garbageyard
  2015-03-27 14:27 ` Stefan Näwe
@ 2015-03-27 16:40 ` Matthieu Moy
  1 sibling, 0 replies; 5+ messages in thread
From: Matthieu Moy @ 2015-03-27 16:40 UTC (permalink / raw)
  To: Garbageyard; +Cc: git

Garbageyard <varuag.chhabra@gmail.com> writes:

> 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/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Change default branch name (server side) while cloning a repository
  2015-03-27 14:27 ` Stefan Näwe
@ 2015-03-27 16:47   ` Jeff King
  0 siblings, 0 replies; 5+ messages in thread
From: Jeff King @ 2015-03-27 16:47 UTC (permalink / raw)
  To: Stefan Näwe; +Cc: Garbageyard, git@vger.kernel.org

On Fri, Mar 27, 2015 at 03:27:27PM +0100, Stefan Näwe wrote:

> > 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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Change default branch name (server side) while cloning a repository
@ 2015-03-29  7:33 Gaurav Chhabra
  0 siblings, 0 replies; 5+ messages in thread
From: Gaurav Chhabra @ 2015-03-29  7:33 UTC (permalink / raw)
  To: git

@Stefan: Thanks for letting me know the version you tried on.

I have the following:
Gitolite version: gitolite3 v3.04-13-gcc9727c-dt on git 1.7.1
Git server version: git version 1.7.1
Git client version: git version 1.9.4.msysgit.2

My Git server version lags quite behind compared to yours. :) Clone of
any repository is not empty because i create non-empty directories
while creating any repository.

@Matthieu: You were right in saying that client can get confused if
several branches point to same commit. :)  Thank a ton! :) Going by
what Jeff mentioned confidently, my server version (1.7.1) indeed has
that flaw.

@Jeff: You've hit the nail on the head! :) Both Matthieu & you are
right. I even confirmed the same by changing the content of mainline
while initializing repository. SHAs indeed became different for both
master and mainline. Now when i clone the repository on my local
machine, it correctly points to mainline. And special thanks for
pointing to the exact Git version where the flaw was fixed. :) I
checked the release notes too. :)

https://git.kernel.org/cgit/git/git.git/tree/Documentation/RelNotes/1.8.4.3.txt

Thank you guys! You rock!!!

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-03-29  7:33 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-29  7:33 Change default branch name (server side) while cloning a repository Gaurav Chhabra
  -- strict thread matches above, loose matches on Subject: below --
2015-03-27 12:27 Garbageyard
2015-03-27 14:27 ` Stefan Näwe
2015-03-27 16:47   ` Jeff King
2015-03-27 16:40 ` Matthieu Moy

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).