I have a git repo that uses a submodule A, and for technical reasons I need to switch the submodule to a submodule B, which is a different repo with different commits, they only shared a couple of commits from the beginning of the project, which is okay to me.
What I've done so far is:
.gitmodules
file to use the new URLrm -rf .git/modules/<submodule>
rm -rf <submodule>
git submodule sync
git submodule update
After that I get an error:
fatal: remote error: upload-pack: not our ref a5129baec669f7736552019baccd3da7e5129cfd
Fetched in submodule path 'Submodule/path', but it did not contain a5129baec669f7736552019baccd3da7e5129cfd. Direct fetching of that commit failed.
So the commit with the SHA a5129b
exists in the submodule A as the most recent commit, but is not in the submodule B.
I don't understand why is trying to fetch the commit from the previous submodule, am I missing something?
I managed to reproduce this and fixed it with these commands:
git submodule set-url <submodule> <old url>
git submodule update
git submodule set-url <submodule> <new url>
git submodule update
git -C <submodule> fetch
git -C <submodule> reset --hard origin/HEAD
WARNING: This will erase any uncommitted changes in submodule
!