{"thread":{"id":"29915","subject":"Git clone behave strange after active branch change in bare repo","startedAt":"2012-03-12T10:10:03Z","lastAt":"2012-03-12T11:12:42Z","messageCount":2,"participants":["Zdenek Crha","Jeff King"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"186689","messageId":"CA+OUE95+Ux_+hSRJw6MH-kh54JewXx-fbWqBoh-Eh_P1tNwAFA@mail.gmail.com","threadId":"29915","inReplyTo":null,"subject":"Git clone behave strange after active branch change in bare repo","fromName":"Zdenek Crha","fromEmail":"zdenek.crha@gmail.com","sentAt":"2012-03-12T10:10:03Z","receivedAt":"2012-03-12T10:10:03Z","isPatch":false,"sender":{"key":"zdenek.crha@gmail.com","avatar":null},"body":"Hello,\n\nI'm trying to change active branch on bare repository to force\ncheckout of different branch than master when directory is cloned. The\ngit version I'm using is  1.7.9.1 from debian repository.\n\nI've used git-symbolic-ref to change active branch without problem:\n\n$ cd repository.git\n$ git branch\n* master\n$ git branch a_branch\n$ git symbolic-ref HEAD refs/heads/a_branch\n$ cat HEAD\nref: refs/heads/a_branch\n\nWhen I run git clone while 'master' and 'a_branch' point to same\ncommit, I will get clone with default branch 'master' where I would\nexpect default branch 'a_branch'.\n\n$ cd .. && git clone repository.git repo\n$ cd repo && git branch\n* master\n\nI've tried to remove master branch and I've got result I've expected -\nnew clone has one branch checked out, the 'a_branch'.\nBut then I created another branch on the commit pointed by active\nbranch and tried to clone:\n\n$ cd repository.git && git branch AAA\n$ cd .. && git clone repository.git\n$ cd repo && git branch\n* AAA\n\nI did few more checks and it seems to me that:\n\n* when active branch is 'master' then default branch in clone is\nalways master as expected\n* when active branch is different from 'master', then the default\nbranch in clone is a first branch in alfabetically sorted list of\nbranches that point to same commit as active branch\n\nIs this behaviour correct or did I run into a bug?\n\nRegards,\nZdenek Crha\n"},{"id":"186691","messageId":"20120312111242.GA12921@sigill.intra.peff.net","threadId":"29915","inReplyTo":"CA+OUE95+Ux_+hSRJw6MH-kh54JewXx-fbWqBoh-Eh_P1tNwAFA@mail.gmail.com","subject":"Re: Git clone behave strange after active branch change in bare repo","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2012-03-12T11:12:42Z","receivedAt":"2012-03-12T11:12:42Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Mon, Mar 12, 2012 at 11:10:03AM +0100, Zdenek Crha wrote:\n\n> When I run git clone while 'master' and 'a_branch' point to same\n> commit, I will get clone with default branch 'master' where I would\n> expect default branch 'a_branch'.\n\nYes, this is a known issue. The git protocol does not transfer the\ncontents of the symref; the client must guess the branch name from the\nset of refs that are advertised. This has been discussed before, and\nthere were even some patches proposed, but I think nobody cared enough\nto push it through, as it requires an extension to the protocol.\n\nYou can search the list archives for past discussions.\n\n> I did few more checks and it seems to me that:\n> \n> * when active branch is 'master' then default branch in clone is\n> always master as expected\n> * when active branch is different from 'master', then the default\n> branch in clone is a first branch in alfabetically sorted list of\n> branches that point to same commit as active branch\n\nExactly. The relevant code is in remote.c:guess_remote_head.\n\n-Peff\n"}]}