How do I replace a git submodule with another repo?

后端 未结 6 1355
野性不改
野性不改 2020-11-28 02:12

How do I replace a git submodule with a different git repo?

Specifically, I have a submodule:

  • located at ./ExternalFrameworks/TestFramework
6条回答
  •  青春惊慌失措
    2020-11-28 02:51

    First, delete the current submodule with the method already mentioned here, which I'm including for convenience:

    • Delete the relevant section from the .gitmodules file
    • Delete the relevant section from .git/config
    • Run git rm --cached path_to_submodule (no trailing slash)
    • Commit and delete the now untracked submodule files

    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 git@github.com:userB/TestFramework.git
    

    and you'll get the submodule loaded at the path you expect.

提交回复
热议问题