Reputation: 411
I have a git repo which has a submodule. The contents of the .gitmodule file for the main repo are:
[submodule "wits-mercuryAPI"]
path = wits-mercuryAPI
url = https://github.com/myorganization/wits-mercuryAPI.git
I would expect that when I issue the command...
git submodule update
... it would correctly clone the submodule from the location specified in the url of the .gitmodule file. However, it apparently tries to use an older version of this file where the url points to an incorrect url, and therefore fails.
For the life of me I can't figure out why it behaves this way or what magic hidden property is telling this command to access some older and invisible version of the .gitmodules file.
Upvotes: 1
Views: 2372
Reputation: 411
Ok, I figured it out. Though I didn't mention this because I didn't think it as relevant, the 'repo' (let's call it 'B') I described in my own quetion was, itself, a submodule of yet another higher-level parent repository (let's call it 'A'). Finally, let's call the submodule described in original question 'C'. So the dependency is A->B->C.
Here's what happened: 1. I updated .gitmodules in B to point to a new and correct url for C and pushed the changes to master. 2. I incorrectly assumed that A would automatically pick up this change if I did: `git clone --recurse . 3. Instead, A "remembers" the version of B that it was pointing to, gets that version of the sub-module with the incorrect url to C
The fix was here: https://gist.github.com/ryannealmes/aa4eed8b222239c9e207
Upvotes: 2
Reputation: 490078
The .gitmodules
file contents are only used when creating the submodule Git repository for the first time. If the submodule repository already exists, Git just keeps using the existing clone.
Depending on the particular version of Git you are using, the submodule repository itself may reside under the .git
directory of the superproject, in .git/modules/
, or (older Git versions) in the path of the submodule itself. In either case, though, if the submodule URL has changed, you have two options:
.git/modules
entry for it) and re-initialize; orgit config
to update this particular clone, e.g., git config remote.origin.url <new-url>
or git config --edit
to open your editor on the configuration.Upvotes: 1