Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to update submodule url in all commits

The Use Case is that i have to move certain repositories to a new server. So these repositories get a new url.
The Parent project which reference these sub-modules needs to be updated with the new url for the sub-module.
I think of doing the following.

  1. update the .gitmodules file
  2. git submodule sync
  3. git submodule update
  4. commit and push

But, since the previous commits have the earlier version of the .gitmodule, if i checkout a previous commit of the parent project - will it not look for the old server?


To ensure reproducibility, we need to have all old commits to be working. Any idea to get around this?

like image 800
maxmelbin Avatar asked Aug 16 '12 12:08

maxmelbin


1 Answers

The URL that's in .gitmodules is generally only used when initializing the submodules or on git submodule sync. On initialization (git submodule init), the URL is put into the repository's .git/config, and when the submodule is cloned into place (on git submodule update) the URL to use is taken from the config. The only other time the URL in .gitmodules is used is when you run git submodule sync, which will similarly update the URL in the config, but also set the origin remote in the submodule to the same URL.

This means that you won't have any problems with checking out an earlier commit and running git submodule update - the remote origin in your submodule isn't changed when you checkout a new commit in the parent repository.

like image 155
Mark Longair Avatar answered Oct 10 '22 19:10

Mark Longair