git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Solved: why cloning my repo always got the wrong default branch; possibly missing featurette?

From
Luke Diamand <luke@diamand.org>
Date
Apr 21, 2012, 08:08 UTC
Message-ID
<4F926B02.3050104@diamand.org>

I've been wondering for a while why it is that when I clone one particular repo, I always end up with HEAD pointed to origin/master regardless of what HEAD *actually* points at (unless I explicitly set the branch I want to checkout on the command line).

i.e.

<on myremote> git symbolic-ref HEAD refs/heads/dev

<on client>
% git clone git://myremote/myrepo
% git branch
* master
% git branch -r
origin/HEAD -> origin/master
origin/foo
origin/bar
origin/dev
...

That doesn't seem right - I thought that setting HEAD on the remote wit git symbolic-ref would set the branch that gets cloned?

Here's what's happening.

git fetches the remote refs. But the field *symref* does not get filled in (at least for git:// and ssh://). So git gets a list of remote refs (HEAD, refs/heads/foo, etc) with no information about whether they are real heads or symrefs.

In wanted_peer_refs(), since I haven't given a branch on the command-line, it then calls guess_remote_head().

guess_remote_head() would get the right answer if head->symref was set:
/*
  * Some transports support directly peeking at
  * where HEAD points; if that is the case, then
  * we don't have to guess.
  */

But in my case it isn't so it then goes and just looks for a head that has the right SHA1.

Unfortunately, my remote 'master' branch and the branch I *really* want to use both usually have the same SHA1. That's because my repo is doing git/p4 mirroring. So the branch I want to use by default ("dev") is being constantly rebased (people push to it and git-p4 then does magic on it after which it matches master again).

i.e. the guess_remote_head() works fine if the branch you want doesn't have the SHA1 as origin/master, but gets it wrong if it does.

I imagine that occasionally when I clone at just the right moment, I *will* get the branch I was expecting!

At a guess, the protocol would need to be changed to put the symbolic ref information in somehow (upload-pack.c, send-refs() ?).

Is this a bug, or a feature?

Thank, Luke

	
Next: Junio C Hamano
Message 1 of 2 in “Solved: why cloning my repo always got the wrong default branch; possibly missing featurette?”
  1. Luke DiamandApr 21, 2012
  2. Junio C HamanoApr 21, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.