{"thread":{"id":"30301","subject":"Solved: why cloning my repo always got the wrong default branch; possibly missing featurette?","startedAt":"2012-04-21T08:08:34Z","lastAt":"2012-04-21T19:28:22Z","messageCount":2,"participants":["Luke Diamand","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"189802","messageId":"4F926B02.3050104@diamand.org","threadId":"30301","inReplyTo":null,"subject":"Solved: why cloning my repo always got the wrong default branch; possibly missing featurette?","fromName":"Luke Diamand","fromEmail":"luke@diamand.org","sentAt":"2012-04-21T08:08:34Z","receivedAt":"2012-04-21T08:08:34Z","isPatch":false,"sender":{"key":"luke@diamand.org","avatar":"https://avatars.githubusercontent.com/u/5330967?v=4"},"body":"I've been wondering for a while why it is that when I clone one \nparticular repo, I always end up with HEAD pointed to origin/master \nregardless of what HEAD *actually* points at (unless I explicitly set \nthe branch I want to checkout on the command line).\n\ni.e.\n\n<on myremote>\ngit symbolic-ref HEAD refs/heads/dev\n\n<on client>\n% git clone git://myremote/myrepo\n% git branch\n* master\n% git branch -r\norigin/HEAD -> origin/master\norigin/foo\norigin/bar\norigin/dev\n...\n\n\nThat doesn't seem right - I thought that setting HEAD on the remote wit \ngit symbolic-ref would set the branch that gets cloned?\n\nHere's what's happening.\n\ngit fetches the remote refs. But the field *symref* does not get filled \nin (at least for git:// and ssh://). So git gets a list of remote refs \n(HEAD, refs/heads/foo, etc) with no information about whether they are \nreal heads or symrefs.\n\nIn wanted_peer_refs(), since I haven't given a branch on the \ncommand-line, it then calls guess_remote_head().\n\nguess_remote_head() would get the right answer if head->symref was set:\n\n/*\n  * Some transports support directly peeking at\n  * where HEAD points; if that is the case, then\n  * we don't have to guess.\n  */\n\n\nBut in my case it isn't so it then goes and just looks for a head that \nhas the right SHA1.\n\nUnfortunately, my remote 'master' branch and the branch I *really* want \nto use both usually have the same SHA1. That's because my repo is doing \ngit/p4 mirroring. So the branch I want to use by default (\"dev\") is \nbeing constantly rebased (people push to it and git-p4 then does magic \non it after which it matches master again).\n\ni.e. the guess_remote_head() works fine if the branch you want doesn't \nhave the SHA1 as origin/master, but gets it wrong if it does.\n\nI imagine that occasionally when I clone at just the right moment, I \n*will* get the branch I was expecting!\n\nAt a guess, the protocol would need to be changed to put the symbolic \nref information in somehow (upload-pack.c, send-refs() ?).\n\nIs this a bug, or a feature?\n\nThank,\nLuke\n\n\n\n\n\n\t\n"},{"id":"189812","messageId":"xmqq7gx8zxyh.fsf@junio.mtv.corp.google.com","threadId":"30301","inReplyTo":"4F926B02.3050104@diamand.org","subject":"Re: Solved: why cloning my repo always got the wrong default branch; possibly missing featurette?","fromName":"Junio C Hamano","fromEmail":"jch@google.com","sentAt":"2012-04-21T19:28:22Z","receivedAt":"2012-04-21T19:28:22Z","isPatch":false,"sender":{"key":"jch@google.com","avatar":null},"body":"Luke Diamand <luke@diamand.org> writes:\n\n> At a guess, the protocol would need to be changed to put the symbolic\n> ref information in somehow (upload-pack.c, send-refs() ?).\n>\n> Is this a bug, or a feature?\n\nKnown protocol limitation, as you already seem to have discovered.\nI think I outlined a possible protocol extension in a message a few\nyears ago, but nobody seemed to be interested/motivated enough, so...\n"}]}