For context: I have a repository which contains a nested submodule.
/superProject
├── moduleA
│ └── moduleB
I need to update the remote URL's for the two submodules to a forked version of both original repositories. I've made the relevant changes in moduleA to reference the new remote URL of moduleB, and the update in the Super Project to reference the new URL and new commit of moduleA.
Now my question is: Say one of the other developers is on an older commit before the submodule updates.
Now if they pull latest, they get an error and their branch isn't updated:
fatal: remote error: upload-pack: not our ref $hash
Git cannot update the commit of moduleA without knowing that it needs to update from the new remote. Which it can't do yet. What is the correct approach to allow developers to update cleanly?
I've tried using combinations of:
git submodule deinit --all -f
git submodule sync --recursive
git submodule update --init --recursive
But I cant seem to find a way to perform this update without deleting the module folder, and then running:
git pull
git submodule sync --recursive
git submodule update --init --recursive
Is there any way to resolve this cleanly? Ideally something that could be put into some type of recipe or even a git alias?
The only way I have found that works in this situation is:
git submodule update --init --recursive
Still open to alternatives because this isn't a great solution if this happens again.