{"thread":{"id":"41193","subject":"Find main branch","startedAt":"2016-01-14T18:17:48Z","lastAt":"2016-01-15T18:02:53Z","messageCount":11,"participants":["pedro rijo","Stefan Beller","Konstantin Khomoutov","Bryan Turner","Jeff King","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"276063","messageId":"CAPMsMoDsay7_n53HY6cxHWEtv5vyugxYUZqwi9tU4dKLv6MGBg@mail.gmail.com","threadId":"41193","inReplyTo":null,"subject":"Find main branch","fromName":"pedro rijo","fromEmail":"pedrorijo91@gmail.com","sentAt":"2016-01-14T18:17:48Z","receivedAt":"2016-01-14T18:17:48Z","isPatch":false,"sender":{"key":"pedrorijo91@gmail.com","avatar":"https://gravatar.com/avatar/a3f4c97ae763402c3ffc08abfec39ef86f6040e34cc9c2a28d36ed10a7a70c91?d=mp&s=160"},"body":"Hey,\n\nIf I clone a repo, the repo will be on a specific branch, the 'main'\n(typically 'master') branch.\n\nIs there any direct command to find that main branch, since that\ninformation is present?\n\nIf so, is there any way to find it without actually cloning the repo\n(similar to git ls-remote)?\n\n-- \nThanks,\n\nPedro Rijo\n"},{"id":"276064","messageId":"CAGZ79kbHSOm3OxEOXUXt0NDTPknyb435w_WOB4XW_-gtt3TH0A@mail.gmail.com","threadId":"41193","inReplyTo":"CAPMsMoDsay7_n53HY6cxHWEtv5vyugxYUZqwi9tU4dKLv6MGBg@mail.gmail.com","subject":"Re: Find main branch","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2016-01-14T18:26:45Z","receivedAt":"2016-01-14T18:26:45Z","isPatch":false,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Looking at the capabilities the server sends you.\n(I forgot if there is a git command for it, but:)\n\n# check for http://github.com/gitster/git\nssh git@github.com git-upload-pack gitster/git\n0104fc10eb5b87a75af2cb93a3932897572f2c544915 HEADmulti_ack thin-pack\nside-band side-band-64k ofs-delta shallow no-progress include-tag\nmulti_ack_detailed symref=HEAD:refs/heads/master\nagent=git/2:2.4.8~peff-symbolic-refs-iii-revenge-of-the-sith-1258-gc4b0e8b\n\nNotice the \"symref=HEAD:refs/heads/master\", which is what you want.\n\nOn Thu, Jan 14, 2016 at 10:17 AM, pedro rijo <pedrorijo91@gmail.com> wrote:\n> Hey,\n>\n> If I clone a repo, the repo will be on a specific branch, the 'main'\n> (typically 'master') branch.\n>\n> Is there any direct command to find that main branch, since that\n> information is present?\n>\n> If so, is there any way to find it without actually cloning the repo\n> (similar to git ls-remote)?\n>\n> --\n> Thanks,\n>\n> Pedro Rijo\n> --\n> To unsubscribe from this list: send the line \"unsubscribe git\" in\n> the body of a message to majordomo@vger.kernel.org\n> More majordomo info at  http://vger.kernel.org/majordomo-info.html\n"},{"id":"276066","messageId":"20160114213113.c700484c7e3acddc467d0e75@domain007.com","threadId":"41193","inReplyTo":"CAPMsMoDsay7_n53HY6cxHWEtv5vyugxYUZqwi9tU4dKLv6MGBg@mail.gmail.com","subject":"Re: Find main branch","fromName":"Konstantin Khomoutov","fromEmail":"kostix+git@007spb.ru","sentAt":"2016-01-14T18:31:13Z","receivedAt":"2016-01-14T18:31:13Z","isPatch":false,"sender":{"key":"kostix+git@007spb.ru","avatar":null},"body":"On Thu, 14 Jan 2016 18:17:48 +0000\npedro rijo <pedrorijo91@gmail.com> wrote:\n\n> If I clone a repo, the repo will be on a specific branch, the 'main'\n> (typically 'master') branch.\n\n`git clone` checks out the branch which is pointed by by the HEAD ref in\nthe source repository.\n\n> Is there any direct command to find that main branch, since that\n> information is present?\n> \n> If so, is there any way to find it without actually cloning the repo\n> (similar to git ls-remote)?\n\nRun `git ls-remote <url>` and, record the SHA1 name of the HEAD ref,\nthen look that name up in the list of the remaining refs.\n"},{"id":"276067","messageId":"CAPMsMoBNzmK618NPP-VXP_70hTxTsa13O9f_usiCPJ-SUOUz_g@mail.gmail.com","threadId":"41193","inReplyTo":"20160114213113.c700484c7e3acddc467d0e75@domain007.com","subject":"Re: Find main branch","fromName":"pedro rijo","fromEmail":"pedrorijo91@gmail.com","sentAt":"2016-01-14T18:40:15Z","receivedAt":"2016-01-14T18:40:15Z","isPatch":false,"sender":{"key":"pedrorijo91@gmail.com","avatar":"https://gravatar.com/avatar/a3f4c97ae763402c3ffc08abfec39ef86f6040e34cc9c2a28d36ed10a7a70c91?d=mp&s=160"},"body":"Stefan Beller solution is based on the server, which may not be very\neasy to do when dealing with Github/Bitbucket/Gitlab and other God\nknows which provider.\n\nKonstantin ls-remote solution is the one I'm already using, but if I\nhave several branches on that commit, I will not be able to decide.\n\nI thought that the 'main' branch information was stored in git, and\npossibly with some way to access it with a git command\n\nThanks,\nPedro Rijo\n\n2016-01-14 18:31 GMT+00:00 Konstantin Khomoutov <kostix+git@007spb.ru>:\n> On Thu, 14 Jan 2016 18:17:48 +0000\n> pedro rijo <pedrorijo91@gmail.com> wrote:\n>\n>> If I clone a repo, the repo will be on a specific branch, the 'main'\n>> (typically 'master') branch.\n>\n> `git clone` checks out the branch which is pointed by by the HEAD ref in\n> the source repository.\n>\n>> Is there any direct command to find that main branch, since that\n>> information is present?\n>>\n>> If so, is there any way to find it without actually cloning the repo\n>> (similar to git ls-remote)?\n>\n> Run `git ls-remote <url>` and, record the SHA1 name of the HEAD ref,\n> then look that name up in the list of the remaining refs.\n\n\n\n-- \nObrigado,\n\nPedro Rijo\n"},{"id":"276069","messageId":"20160114215312.255f26416bb93beb2e18f1f2@domain007.com","threadId":"41193","inReplyTo":"CAPMsMoBNzmK618NPP-VXP_70hTxTsa13O9f_usiCPJ-SUOUz_g@mail.gmail.com","subject":"Re: Find main branch","fromName":"Konstantin Khomoutov","fromEmail":"kostix+git@007spb.ru","sentAt":"2016-01-14T18:53:12Z","receivedAt":"2016-01-14T18:53:12Z","isPatch":false,"sender":{"key":"kostix+git@007spb.ru","avatar":null},"body":"On Thu, 14 Jan 2016 18:40:15 +0000\npedro rijo <pedrorijo91@gmail.com> wrote:\n\n> Stefan Beller solution is based on the server, which may not be very\n> easy to do when dealing with Github/Bitbucket/Gitlab and other God\n> knows which provider.\n> \n> Konstantin ls-remote solution is the one I'm already using, but if I\n> have several branches on that commit, I will not be able to decide.\n> \n> I thought that the 'main' branch information was stored in git, and\n> possibly with some way to access it with a git command\n\nIt *is* stored in the Git repository -- in the HEAD ref.\nThe question of how to retreive precisely this bit of information --\nI don't really know.  Basically you want `git show-remote-ref --head`\nbut Git does not have such a command, only `git show-ref` ;-)\n"},{"id":"276070","messageId":"CAGyf7-H2jSW0vJZ7ng1OcN7X5tvs+sEuGUH4yMSpJ_-wwUcoTQ@mail.gmail.com","threadId":"41193","inReplyTo":"CAPMsMoBNzmK618NPP-VXP_70hTxTsa13O9f_usiCPJ-SUOUz_g@mail.gmail.com","subject":"Re: Find main branch","fromName":"Bryan Turner","fromEmail":"bturner@atlassian.com","sentAt":"2016-01-14T19:12:35Z","receivedAt":"2016-01-14T19:12:35Z","isPatch":false,"sender":{"key":"bturner@atlassian.com","avatar":"https://gravatar.com/avatar/16bcf3167981c1ef7c804e502642366d888a35b0d0b0a4ca01fdc442aa1acb1e?d=mp&s=160"},"body":"On Thu, Jan 14, 2016 at 11:40 AM, pedro rijo <pedrorijo91@gmail.com> wrote:\n> Stefan Beller solution is based on the server, which may not be very\n> easy to do when dealing with Github/Bitbucket/Gitlab and other God\n> knows which provider.\n>\n> Konstantin ls-remote solution is the one I'm already using, but if I\n> have several branches on that commit, I will not be able to decide.\n>\n> I thought that the 'main' branch information was stored in git, and\n> possibly with some way to access it with a git command\n\nIt is, but unfortunately it's not stored in a way that a remote client\ncan (easily) retrieve using porcelain commands. The HEAD ref on the\nremote is the \"main\" branch, but, as Konstantin's ls-remote command\nshows, the actual wire protocol data for HEAD is the SHA-1 of the tip\ncommit for the branch, not the name.\n\nAs Stefan indicated, the way this is messaged to the client from the\nserver is in the capabilities sent. There's generally not a good way\nto see this. However, one thing that you might try (assuming the\nyou're using HTTPS to talk to the repository and you're on MacOS or\nLinux) is to manually run git-remote-https. For example, here's output\nfor the atlassian/atlassian-refapp repository on Bitbucket:\n\nbturner@ubuntu:~$ git remote-https\nhttps://bitbucket.org/atlassian/atlassian-refapp.git\nhttps://bitbucket.org/atlassian/atlassian-refapp.git | head\nlist\n@refs/heads/master HEAD\nd9330a80b50b92b91bb82834f052e9c86ed55452 refs/heads/2.14-beta1\ndb3dbe4b6549d0ac1437415dbf1ffb750e33e28b\nrefs/heads/JDEV-32966-fix-xsrfrequestvalidatortest\ne0331e00e5e73cd463f12c2947ef567edbb6b9f8 refs/heads/atlassian-refapp-2.2.7.x\ne0e562acf9fbdf5255a503a0916a06c52fc456be refs/heads/atlassian-refapp-2.2.x\n\n(Note that the repetition of the remote URL here is necessary.) \"git\nremote-https\" is an interactive process, so when you first run it it\nwon't do anything. \"list\" is a command I sent to the \"git\nremote-https\" process that's running. That leading \"@refs/heads/master\nHEAD\" means the remote HEAD is a symbolic ref pointing at the master\nbranch. So master is the \"main\" branch.\n\nThe same thing works for GitHub. Here's the hazelcast/hazelcast repository:\n\nbturner@ubuntu:~$ git remote-https\nhttps://github.com/hazelcast/hazelcast.git\nhttps://github.com/hazelcast/hazelcast.git | head\nlist\n@refs/heads/master HEAD\n988810c4b5c5195412c65357e06cbb0e51173258 refs/heads/3.1.8\nbddfb328e4779bccec6f7788c94960f6292b02c9 refs/heads/3.2-fix-eacg\n84e7d1006cd342c39afdf0ac520b5b04b8233d75 refs/heads/3.3.6\n2e4ffc4f593de0869f0db9f7224f964f72dac15d refs/heads/3.4-gem\nd0a7d416b1220ef4badd98e42991dabe34c7beeb refs/heads/3.5.1\n6a13721d33bdb07de23f5c505b689e2ee50d5abb refs/heads/3.5.3-ercssn\n56676b20baae8668e731f17c9f3b9844ddd486d0 refs/heads/3.5.4\n\nI'm not aware of a simple equivalent for SSH. Also, note that this\n\"git remote-https\" trick won't work on Windows. When you hit Enter\nafter \"list\" it writes a CRLF, so the \"git-remote-https\" process\ncompares \"listCR\" against its list of known commands and finds no\nmatch.\n\nHope this helps!\nBryan Turner\n\n>\n> Thanks,\n> Pedro Rijo\n>\n"},{"id":"276081","messageId":"20160114210452.GA10825@sigill.intra.peff.net","threadId":"41193","inReplyTo":"CAPMsMoBNzmK618NPP-VXP_70hTxTsa13O9f_usiCPJ-SUOUz_g@mail.gmail.com","subject":"Re: Find main branch","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2016-01-14T21:04:52Z","receivedAt":"2016-01-14T21:04:52Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Thu, Jan 14, 2016 at 06:40:15PM +0000, pedro rijo wrote:\n\n> Stefan Beller solution is based on the server, which may not be very\n> easy to do when dealing with Github/Bitbucket/Gitlab and other God\n> knows which provider.\n> \n> Konstantin ls-remote solution is the one I'm already using, but if I\n> have several branches on that commit, I will not be able to decide.\n\nRight. Git used to guess, but that was not great exactly because of the\nambiguity you have seen. Servers started publishing the value of the\nHEAD symref in git v1.8.4.3. I'd expect that to be available on any\nmodern server.\n\nThere's unfortunately not a plumbing command to directly access the\nvalue, but \"git remote set-head $remote -a\" will query the remote and\nupdate refs/remotes/$remote/HEAD appropriately. As a bonus, if it's an\nolder server that doesn't provide the HEAD value, it will fallback to\nthe \"old\" heuristics (see guess_remote_head for details).\n\n-Peff\n"},{"id":"276082","messageId":"20160114211335.GB10825@sigill.intra.peff.net","threadId":"41193","inReplyTo":"CAGyf7-H2jSW0vJZ7ng1OcN7X5tvs+sEuGUH4yMSpJ_-wwUcoTQ@mail.gmail.com","subject":"Re: Find main branch","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2016-01-14T21:13:35Z","receivedAt":"2016-01-14T21:13:35Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Thu, Jan 14, 2016 at 12:12:35PM -0700, Bryan Turner wrote:\n\n> The same thing works for GitHub. Here's the hazelcast/hazelcast repository:\n> \n> bturner@ubuntu:~$ git remote-https\n> https://github.com/hazelcast/hazelcast.git\n> https://github.com/hazelcast/hazelcast.git | head\n> list\n> @refs/heads/master HEAD\n> 988810c4b5c5195412c65357e06cbb0e51173258 refs/heads/3.1.8\n> bddfb328e4779bccec6f7788c94960f6292b02c9 refs/heads/3.2-fix-eacg\n> 84e7d1006cd342c39afdf0ac520b5b04b8233d75 refs/heads/3.3.6\n> 2e4ffc4f593de0869f0db9f7224f964f72dac15d refs/heads/3.4-gem\n> d0a7d416b1220ef4badd98e42991dabe34c7beeb refs/heads/3.5.1\n> 6a13721d33bdb07de23f5c505b689e2ee50d5abb refs/heads/3.5.3-ercssn\n> 56676b20baae8668e731f17c9f3b9844ddd486d0 refs/heads/3.5.4\n> \n> I'm not aware of a simple equivalent for SSH. Also, note that this\n> \"git remote-https\" trick won't work on Windows. When you hit Enter\n> after \"list\" it writes a CRLF, so the \"git-remote-https\" process\n> compares \"listCR\" against its list of known commands and finds no\n> match.\n\nThere's no equivalent for ssh, because you're hooking in at the\nremote-helper layer, and ssh (and git://) are builtins, and http is not.\n\nI mentioned \"git remote\" elsewhere in the thread, which is probably the\nleast gross way (it's just ugly because it writes to a file instead of\nto stdout). But you can also snoop on the protocol:\n\n  $ GIT_TRACE_PACKET=3 git ls-remote origin 3>&1 >/dev/null |\n    perl -lne '/symref=(\\S+)/ and print $1'\n  HEAD:refs/heads/master\n\nIt would be nice if \"git ls-remote\" just had some way of printing the\ncapabilities.\n\n-Peff\n"},{"id":"276145","messageId":"CAPMsMoCHYEqSoR5UKBVK7yqSK=itRXxDDV0Kp7xwoykYRpzfWg@mail.gmail.com","threadId":"41193","inReplyTo":"20160114211335.GB10825@sigill.intra.peff.net","subject":"Re: Find main branch","fromName":"pedro rijo","fromEmail":"pedrorijo91@gmail.com","sentAt":"2016-01-15T10:49:02Z","receivedAt":"2016-01-15T10:49:02Z","isPatch":false,"sender":{"key":"pedrorijo91@gmail.com","avatar":"https://gravatar.com/avatar/a3f4c97ae763402c3ffc08abfec39ef86f6040e34cc9c2a28d36ed10a7a70c91?d=mp&s=160"},"body":"Thanks guys, the last answer seems to work !\n\nWouldn't mind to have a git command that returned the main branch though :p\n\nThanks,\nPedro Rijo\n\n2016-01-14 21:13 GMT+00:00 Jeff King <peff@peff.net>:\n> On Thu, Jan 14, 2016 at 12:12:35PM -0700, Bryan Turner wrote:\n>\n>> The same thing works for GitHub. Here's the hazelcast/hazelcast repository:\n>>\n>> bturner@ubuntu:~$ git remote-https\n>> https://github.com/hazelcast/hazelcast.git\n>> https://github.com/hazelcast/hazelcast.git | head\n>> list\n>> @refs/heads/master HEAD\n>> 988810c4b5c5195412c65357e06cbb0e51173258 refs/heads/3.1.8\n>> bddfb328e4779bccec6f7788c94960f6292b02c9 refs/heads/3.2-fix-eacg\n>> 84e7d1006cd342c39afdf0ac520b5b04b8233d75 refs/heads/3.3.6\n>> 2e4ffc4f593de0869f0db9f7224f964f72dac15d refs/heads/3.4-gem\n>> d0a7d416b1220ef4badd98e42991dabe34c7beeb refs/heads/3.5.1\n>> 6a13721d33bdb07de23f5c505b689e2ee50d5abb refs/heads/3.5.3-ercssn\n>> 56676b20baae8668e731f17c9f3b9844ddd486d0 refs/heads/3.5.4\n>>\n>> I'm not aware of a simple equivalent for SSH. Also, note that this\n>> \"git remote-https\" trick won't work on Windows. When you hit Enter\n>> after \"list\" it writes a CRLF, so the \"git-remote-https\" process\n>> compares \"listCR\" against its list of known commands and finds no\n>> match.\n>\n> There's no equivalent for ssh, because you're hooking in at the\n> remote-helper layer, and ssh (and git://) are builtins, and http is not.\n>\n> I mentioned \"git remote\" elsewhere in the thread, which is probably the\n> least gross way (it's just ugly because it writes to a file instead of\n> to stdout). But you can also snoop on the protocol:\n>\n>   $ GIT_TRACE_PACKET=3 git ls-remote origin 3>&1 >/dev/null |\n>     perl -lne '/symref=(\\S+)/ and print $1'\n>   HEAD:refs/heads/master\n>\n> It would be nice if \"git ls-remote\" just had some way of printing the\n> capabilities.\n>\n> -Peff\n\n\n\n-- \nObrigado,\n\nPedro Rijo\n"},{"id":"276176","messageId":"xmqq1t9ikaxb.fsf@gitster.mtv.corp.google.com","threadId":"41193","inReplyTo":"20160114211335.GB10825@sigill.intra.peff.net","subject":"Re: Find main branch","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2016-01-15T17:30:24Z","receivedAt":"2016-01-15T17:30:24Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jeff King <peff@peff.net> writes:\n\n> It would be nice if \"git ls-remote\" just had some way of printing the\n> capabilities.\n\nI would agree that it would be nice to give an option to ls-remote\nto show which ones are symrefs pointing at what.  You are being more\nambitious than that, but I am not sure I would agree it is a good\nidea.\n\nMost normal capabilities have no value to ordinary end users, and\nthe symref= thing is interesting for them only because there isn't\nsuch an option in ls-remote (hence \"capabilities\" thing could be\nused as a poor-man's substitute).\n"},{"id":"276181","messageId":"20160115180253.GA9590@sigill.intra.peff.net","threadId":"41193","inReplyTo":"xmqq1t9ikaxb.fsf@gitster.mtv.corp.google.com","subject":"Re: Find main branch","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2016-01-15T18:02:53Z","receivedAt":"2016-01-15T18:02:53Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Fri, Jan 15, 2016 at 09:30:24AM -0800, Junio C Hamano wrote:\n\n> Jeff King <peff@peff.net> writes:\n> \n> > It would be nice if \"git ls-remote\" just had some way of printing the\n> > capabilities.\n> \n> I would agree that it would be nice to give an option to ls-remote\n> to show which ones are symrefs pointing at what.  You are being more\n> ambitious than that, but I am not sure I would agree it is a good\n> idea.\n> \n> Most normal capabilities have no value to ordinary end users, and\n> the symref= thing is interesting for them only because there isn't\n> such an option in ls-remote (hence \"capabilities\" thing could be\n> used as a poor-man's substitute).\n\nI thought it might be nice for any porcelain which tries to wrap\n`ls-remote`, make some decision based on the capabilities, and then\ninvoke another plumbing command. But I guess that is probably slightly\ncrazy, and nobody is doing it.\n\nSomething like `ls-remote --symrefs` probably would be a better place to\nstart.\n\n-Peff\n"}]}