How to change the remote repository for a git submodule?

I’ve created a git repository with a submodule in it. I’m able to tell the submodule itself to change its remote repository path, but I’m not sure how to tell the parent repository how to change the remote repository path for the submodule.

I wouldn’t be surprised if I’m somewhat out of luck and have to do things manually, as even deleting submodules isn’t easy.

9 s
9

You should just be able to edit the .gitmodules file to update the URL and then run git submodule sync --recursive to reflect that change to the superproject and your working copy.

Then you need to go to the .git/modules/path_to_submodule dir and change its config file to update git path.

If repo history is different then you need to checkout new branch manually:

git submodule sync --recursive
cd <submodule_dir> 

git fetch
git checkout origin/master
git branch master -f
git checkout master

Leave a Comment