How do I replace a git submodule with a different git repo?
Specifically, I have a submodule:
./ExternalFrameworks/TestFramework
that points to a git repo [email protected]:userA/TestFramework.git
[email protected]:userB/TestFramework.git
.The problem is that when I delete the submodule with the method described here, then re-add it using the command
git submodule add [email protected]:userB/TestFramework.git
I get this error:
A git directory for 'ExternalFrameworks/TestFramework' is found locally with remote(s):
origin [email protected]:userA/TestFramework.git
If you want to reuse this local git directory instead of cloning again from
[email protected]:userB/TestFramework.git
use the '--force' option. If the local git directory is not the correct repo
or you are unsure what this means choose another name with the '--name' option.
Git Submodules Moving a submodule If needed, create the parent directory of the new location of the submodule ( mkdir -p new/path/to ). Move all content from the old to the new directory ( mv -vi old/path/to/module new/path/to/submodule ). Make sure Git tracks this directory ( git add new/path/to ).
If the location (URL) of the submodule has changed, then you can simply:
.gitmodules
file in the repo root to use the new URL.rm -rf .git/modules/<submodule>
.rm -rf <submodule>
.git submodule sync
.git submodule update
.More complete info can be found elsewhere:
First, delete the current submodule with the method already mentioned here, which I'm including for convenience:
.gitmodules
file.git/config
git rm --cached path_to_submodule
(no trailing slash)Now, add the new submodule with the --name
flag. This will give git an alternate name to reference in .git/config
for the submodule, to deconflict with the submodule that was there historically, which you still want to work in your prior history.
So type:
git submodule add --name UpdatedTestFramework [email protected]:userB/TestFramework.git
and you'll get the submodule loaded at the path you expect.
These commands will do the work on command prompt without altering any files on local repository.
git config --file=.gitmodules submodule.Submod.url https://github.com/username/ABC.git
git config --file=.gitmodules submodule.Submod.branch Dev
git submodule sync
git submodule update --init --recursive --remote
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With