Search code examples
gitgit-submodules

What is the point of 'git submodule init'?


Background

To populate a repository's submodules, one typically invokes:

git submodule init
git submodule update

In this usage, git submodule init seems to do only one thing: populate .git/config with information that is already in .gitmodules.

What is the point of that?

Couldn't git submodule update simply use the information from .gitmodules? This would avoid both:

  • an unnecessary command (git submodule init); and
  • an unnecessary duplication of data (.gitmodules content into .git/config).

Question

Either:

  • there are use-cases for git submodule init that I do not know (in which case, please enlighten me!); or else
  • git submodule init is cruft that could be deprecated in Git without any harm.

Which of these is true?


Solution

  • Reading the git submodule documentation, there is a use-case that ostensibly justifies the existence of git submodule init as a standalone command.

    If a user who has cloned a repository wishes to use a different URL for a submodule than is specified by the upstream repository, then that user can:

    git submodule init
    vim .git/config # Alter submodule URL as desired, without changing .gitmodules
                    # or polluting history.
    git submodule update