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

Re: Find main branch

From
Bryan Turner <bturner@atlassian.com>
Date
Jan 14, 2016, 19:12 UTC
Message-ID
<CAGyf7-H2jSW0vJZ7ng1OcN7X5tvs+sEuGUH4yMSpJ_-wwUcoTQ@mail.gmail.com>
In-Reply-To
<CAPMsMoBNzmK618NPP-VXP_70hTxTsa13O9f_usiCPJ-SUOUz_g@mail.gmail.com>
On Thu, Jan 14, 2016 at 11:40 AM, pedro rijo <pedrorijo91@gmail.com> wrote:
Show 9 quoted lines
> Stefan Beller solution is based on the server, which may not be very
> easy to do when dealing with Github/Bitbucket/Gitlab and other God
> knows which provider.
>
> Konstantin ls-remote solution is the one I'm already using, but if I
> have several branches on that commit, I will not be able to decide.
>
> I thought that the 'main' branch information was stored in git, and
> possibly with some way to access it with a git command

It is, but unfortunately it's not stored in a way that a remote client can (easily) retrieve using porcelain commands. The HEAD ref on the remote is the "main" branch, but, as Konstantin's ls-remote command shows, the actual wire protocol data for HEAD is the SHA-1 of the tip commit for the branch, not the name.

As Stefan indicated, the way this is messaged to the client from the server is in the capabilities sent. There's generally not a good way to see this. However, one thing that you might try (assuming the you're using HTTPS to talk to the repository and you're on MacOS or Linux) is to manually run git-remote-https. For example, here's output for the atlassian/atlassian-refapp repository on Bitbucket:

bturner@ubuntu:~$ git remote-https https://bitbucket.org/atlassian/atlassian-refapp.git https://bitbucket.org/atlassian/atlassian-refapp.git | head list @refs/heads/master HEAD d9330a80b50b92b91bb82834f052e9c86ed55452 refs/heads/2.14-beta1 db3dbe4b6549d0ac1437415dbf1ffb750e33e28b refs/heads/JDEV-32966-fix-xsrfrequestvalidatortest e0331e00e5e73cd463f12c2947ef567edbb6b9f8 refs/heads/atlassian-refapp-2.2.7.x e0e562acf9fbdf5255a503a0916a06c52fc456be refs/heads/atlassian-refapp-2.2.x

(Note that the repetition of the remote URL here is necessary.) "git remote-https" is an interactive process, so when you first run it it won't do anything. "list" is a command I sent to the "git remote-https" process that's running. That leading "@refs/heads/master HEAD" means the remote HEAD is a symbolic ref pointing at the master branch. So master is the "main" branch.

The same thing works for GitHub. Here's the hazelcast/hazelcast repository:

bturner@ubuntu:~$ git remote-https https://github.com/hazelcast/hazelcast.git https://github.com/hazelcast/hazelcast.git | head list @refs/heads/master HEAD 988810c4b5c5195412c65357e06cbb0e51173258 refs/heads/3.1.8 bddfb328e4779bccec6f7788c94960f6292b02c9 refs/heads/3.2-fix-eacg 84e7d1006cd342c39afdf0ac520b5b04b8233d75 refs/heads/3.3.6 2e4ffc4f593de0869f0db9f7224f964f72dac15d refs/heads/3.4-gem d0a7d416b1220ef4badd98e42991dabe34c7beeb refs/heads/3.5.1 6a13721d33bdb07de23f5c505b689e2ee50d5abb refs/heads/3.5.3-ercssn 56676b20baae8668e731f17c9f3b9844ddd486d0 refs/heads/3.5.4

I'm not aware of a simple equivalent for SSH. Also, note that this "git remote-https" trick won't work on Windows. When you hit Enter after "list" it writes a CRLF, so the "git-remote-https" process compares "listCR" against its list of known commands and finds no match.

Hope this helps! Bryan Turner

>
> Thanks,
> Pedro Rijo
>
Previous: Konstantin KhomoutovNext: Jeff King
Message 6 of 11 in “Find main branch”
  1. pedro rijoJan 14, 2016
  2. Stefan BellerJan 14, 2016
  3. Konstantin KhomoutovJan 14, 2016
  4. pedro rijoJan 14, 2016
  5. Konstantin KhomoutovJan 14, 2016
  6. Bryan TurnerJan 14, 2016
  7. Jeff KingJan 14, 2016
  8. pedro rijoJan 15, 2016
  9. Junio C HamanoJan 15, 2016
  10. Jeff KingJan 15, 2016
  11. Jeff KingJan 14, 2016

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.