Subject: Re: How should submodules use different sshCommand during initial update?

From: Jeff King <[email-masked]>
Date: Tue, 14 Apr 2026 02:15:58 -0400

On Tue, Apr 14, 2026 at 09:28:20AM +0800, Shibo Xia wrote:

> My concern is that this still solves the problem indirectly through URL
> rewriting / SSH host aliasing, rather than allowing the submodule's SSH
> behavior itself to be configured more directly.
> 
> So I think this answers the practical "how can this be done today?" part,
> but I am still wondering whether there is a reason Git should not support a
> more direct per-submodule sshCommand-style configuration.

For arbitrary per-submodule config, I can think of two approaches:

One is conditional includeIf directives in your ~/.gitconfig, matching
based on the submodule names. Like:

  # replace PARENT and SUBMODULE with your filesystem names
  [includeIf "gitdir:**/PARENT/.git/modules/SUBMODULE"]
  path = .gitconfig-submodule

and then in ~/.gitconfig-submodule, you'd have:

  [core]
  sshCommand = whatever

This works, but it's kind of gross, as it depends on the module naming
scheme (and isn't there a proposal to make these more opaque? I didn't
follow it). And of course you're not actually putting the config in the
submodule, but rather polluting your user-level config with it (which
might or might not be preferable, depending on what you're trying to
configure).

The second thought is that we faced the same problem with "git clone"
itself: you might want to tweak some config after the repo is
initialized but before we fetch anything. We added the "clone -c" option
for that. It would seem reasonable to me to have a similar option that
is passed along to git-clone under the hood. We already have ways to
pass through options like --single-branch for the same reason.

And then presumably you could do:

  git submodule update --init -c core.sshCommand=whatever

In the meantime, as a workaround I suspect you could do it in two steps,
like:

  # set it for the initial clone; this is using the one-shot "git -c",
  # not "clone -c" that will actually save the result in the
  # new repo
  git -c core.sshCommand=whatever submodule update --init

  # and then save it for subsequent fetches
  git submodule foreach 'git config core.sshCommand whatever'

It's rather unwieldy. And I think gets weird if you want to cover only a
subset of paths, as it doesn't look like "submodule foreach" allows
that. So you might be stuck with:

  git -c core.sshCommand=whatever submodule update --init some-path
  git -C .git/modules/some-path config core.sshCommand whatever

which is back to being overly intimate with the filesystem layout. There
might be a better way to do a per-module command. I don't really use
submodules myself.

-Peff