1

Note: The question is about using git submodule update without the --remote flag.

The documentation for git submodule update says the following:

Update the registered submodules to match what the superproject expects by cloning missing submodules, fetching missing commits in submodules and updating the working tree of the submodules.

What I don’t understand is how Git decides which remote to use for fetching in a submodule. Does Git take the URL for the submodule from .gitmodules/.git/config of the supermodule and then fetch missing commits from that URL?

I am confused because documentation states that this URL is only used when a submodule is missing, that is, for its cloning:

submodule.<name>.url

Defines a URL from which the submodule repository can be cloned. This may be either an absolute URL ready to be passed to git-clone[1] or (if it begins with ./ or ../) a location relative to the superproject’s origin repository.

Does it perhaps use a standard rule for git fetch in a submodule?

When no remote is specified, by default the origin remote will be used, unless there’s an upstream branch configured for the current branch.

Thus, if I am currently checked-out in a submodule on a branch that does not have an upstream branch, git submodule update command uses the submodule's origin remote. However, if I am currently checked-out in a submodule on a branch random-main that follows (has upstream) remote-tracking branch random/main, then git submodule update command uses the submodule's random remote for fetching.

3
  • A submodule is just a repo,, there's nothing unusual about it. Git cd's in and fetches for you, using whatever options you asked for on the command line or configured in the submodule. Commented Sep 5, 2025 at 20:30
  • @jthill So git submodule update is something like cd path/to/submodule && git fetch therefor it uses rules for fetch command: "When no remote is specified, by default the origin remote will be used, unless there’s an upstream branch configured for the current branch." Commented Sep 5, 2025 at 21:12
  • @jthill "Git cd's in and fetches for you ..." - but from which repo? It won't just use origin set by initial git submodule init && git submodule update, but decide based on current checkout-out branch, right? Commented Sep 5, 2025 at 21:20

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.