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

Re: Name for initial branch is ignored when repository is cloned with SSH

From
Jeff King <peff@peff.net>
Date
Mar 15, 2024, 05:49 UTC
Message-ID
<20240315054936.GA1741107@coredump.intra.peff.net>
In-Reply-To
<20240315.104939.1269594475664662053.yasu@utahime.org>
On Fri, Mar 15, 2024 at 10:49:39AM +0900, Yasuhiro Kimura wrote:
Show 10 quoted lines
> I expect the change is committed to 'main' branch. But actually it is
> committed to 'master' branch.
> 
> Anything else you want to add:
> 
> If I change step 2 as following,
> 
> 2'. git clone /somewhere/test.git
> 
> then I get expected behavior.
I suspect you are running afoul of two things:
  1. When cloning a totally empty repository, detecting the destination
     of the unborn HEAD requires a protocol extension. This extension
     was implemented only for Git's v2 protocol, not for v0.
  2. Git should automatically use v2 in most cases these days. But it
     does so by probing the server in a backwards-compatible way to see
     if it also supports v2. For ssh, that probe happens by passing a
     special environment variable. However, the default config for many
     ssh servers refuses unknown variables. For OpenSSH, you'd want to
     add:
       AcceptEnv GIT_PROTOCOL
     to your sshd_config.

You can verify the protocol in use by running your clone with GIT_TRACE_PACKET=1 in the environment. For v0, you'll see either a pair of empty flush packets (for older versions of the server):

  packet:        clone< 0000
  packet:        clone> 0000
or a single-line capabilities faux-ref like:
  packet:        clone< 00000... capabilities^{}\0multi_ack thin-pack side-band etc...

For v2, the server will respond with a multi-line capabilities list, starting with the version:

  packet:        clone< version 2

Assuming my guess is right, I think everything here is working as designed, though obviously it's not a great outcome (and changing the server-side config may not be an option for everyone).

Some possible things we could do to make it better:
  a. teach v0 the same "unborn" extension that v2 knows (or maybe even
     the existing symref extension would work on the capabilities line?)
     This probably wouldn't be too hard, but I think there are many
     other capabilities that v0 would still lack, so it's kind of a
     losing battle.
  b. as v0-only servers become more and more rare, it would be nice if
     the client could start assuming v2 by default, rather than probing.
     But I don't think this quite works, because it is the server who
     starts speaking v2 first (and it won't do so without seeing that
     probe). You could imagine the client invoking "git-upload-pack
     --version=2" on the server, but of course no server implements that
     option yet (and if you added it, you'd have to wait for the server
     side support to percolate).
  c. provide more ways to get the v2 probe information to the server.
     For ssh, one obvious thing is to invoke "GIT_PROTOCOL=version=2
     git-upload-pack" on the server, using the shell to set the
     environment variable rather than passing it over ssh. We didn't do
     that when we added v2 because there are backwards compatibility
     failure modes (e.g., servers where the shell is not regular 'sh' or
     where there might not be a shell at all, or restricted environments
     which allow "git-upload-pack" to run but nothing else).

But maybe taking (b) and (c) together, we could add an option to ask the client to pass the protocol variable via the shell. It doesn't have to work everywhere because you'd enable it manually for servers where you know it would work (and people configuring restricted servers probably already made the necessary ssh config changes).

Of course the biggest challenging is users realizing that they need to do something to enable v2 in the first place. For the most part v0 just works, and so it is easy to not realize you're still using it.

-Peff
Previous: Yasuhiro KimuraNext: Marc Branchaud
Message 2 of 3 in “Name for initial branch is ignored when repository is cloned with SSH”
  1. Yasuhiro KimuraMar 15, 2024
  2. Jeff KingMar 15, 2024
  3. sshd support for Git protocol v2 (was: Re: Name for initial branch is ignored when repository is cloned with SSH)Marc Branchaud, Mar 15, 2024

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.