Skip to content

Instantly share code, notes, and snippets.

@DavidEGrayson
Created June 1, 2023 18:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DavidEGrayson/6b9f2bda5962587827fe1f02be2c568c to your computer and use it in GitHub Desktop.
Save DavidEGrayson/6b9f2bda5962587827fe1f02be2c568c to your computer and use it in GitHub Desktop.
Git submodule notes

Submodule URL

There are three locations where git keeps track of submodule URL:

  1. .gitmodules - This is a regular file that is committed in the repository.
  2. .git/config
  3. .git/modules/somepath/config
These commands have an effect on the three URLs:

  • git submodule init somepath : Copies #1 into #2 if #2 does NOT already exist. (The documentation is wrong and makes it sound like it always sets #2.)
  • git submodule sync somepath : Copies #1 into #2 if #2 already exists.
  • git submodule set-url somepath someurl : Sets #1, and also syncs (see above).
  • git submodule deinit somepath : Clears #2 (leaves #3 around!)
  • git config submodule.somepath.url someurl : Sets #2.
  • git submodule update somepath : Copies #2 into #3 if #3 does NOT already exist. (e.g. If you haven't cloned the repo yet, clones it using #2.)
There seems to be no easy command for updating #3.

See also

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment