im working on a project with some submodules, but for this question lets say i only have one
Im going to call my “parent repo” as PR and my submodule as “SM”
Lets say two dudes have a clone of the PR, but one of the change the url of the repo; although he can do a manual change to the .gitmodules file (changing the URL os the SM) and then :
git submodule sync SM
He prefers to do a
git submodule set-url SM newUrl
And then he wants to rename the SM to “SMX” so he does a:
git mv SM SMX
(For what i know, by checking the .gitmodules and .git/config, everuthing is fine till this point right?)
So then he does a :
git submodule update --remote
To update his local SMX directory
He commits everything and decide to push it
So now, i have my own copy and i notice this changes to the remote PR.
For what i read in the “Pro GIT” book:
There is a special situation that can happen when pulling superproject updates: it could be that the upstream repository has changed the URL of the submodule in the .gitmodules file in one of the commits you pull. This can happen for example if the submodule project changes its hosting platform. In that case, it is possible for git pull –recurse-submodules, or git submodule update, to fail if the superproject references a submodule commit that is not found in the submodule remote locally configured in your repository. In order to remedy this situation, the git submodule sync command is required:
# copy the new URL to your local config
$ git submodule sync --recursive
# update the submodule from the new URL
$ git submodule update --init --recursive
Soooooooo, for the
git submodule sync
The Git documentation says this:
Synchronizes submodules’ remote URL configuration setting to the value specified in .gitmodules. It will only affect those submodules which already have a URL entry in .git/config (that is the case when they are initialized or freshly added)
Sooooo, because i already had initialized the SM submodule i my local copy, when i do a
git pull origin
And then a
git submodule sync --recursive
Now my .gitmodules is synchronized with my local .git/config (I GUESS, LET ME SEE IF IM WRONG PLEASE)
So now if i do a
git submodule update --init --recursive
(I think, in this particular case a ‘git submodule update’ or ‘git submodule update –remote’ will work just fine, but ‘git submodule update –init –recursive’ will work too but is in this particular case not the best choice)
I will update my local SM -> SMX right?, but it gives me this output
fatal: remote error: upload-pack: not our ref cee0718a58c2f7dc4a8d29da5b9ede1354bc153c
fatal: Fetched in submodule path ‘SMX’, but it did not contain cee0718a58c2f7dc4a8d29da5b9ede1354bc153c. Direct fetching of that commit failed.
The i tried with
git submodule update --remote
And this gives me no error but it doesnt do anything, it doesnt upate my local SM to SMX
I want to clarify that in my PR in GITHUB the pushed commit of my partner its good, i mean, in the PR, the reference to SMX works fine, with this i mean that, this reference “cee0718a58c2f7dc4a8d29da5b9ede1354bc153c” does exists in SMX submodule
So why is this happenning? is this happening because of changing the submodule name (in this example from SM to SMX)?
Why is this happening and how to solve it?
Thanks in advance !!