Git submodule change remote

Git submodules can switch remotes. This is useful when making a pull request for a project that relies on another pull request submodule. Verify the change in the top project’s “.gitmodules” file.

Example: suppose the directory “subdir” is a Git submodule. In this command, do not put “./subdir” or “subdir/”, just “subdir” by itself. Suppose you also wish to change the branch to “feat1” in the submodule.

git submodule set-url -- subdir https://github.invalid/username/new

git submodule sync

git -C subdir pull

git -C subdir switch feat1