Search code examples
gitgit-submodules

Can I make a "deep copy" of a git repository with submodules?


It is easy to clone an entire project plus all its submodules:

git clone --recursive [email protected]:homer/powerplant.git

However, how do I create a clone that has all these submodules replaced by the HEADs of the individual sub-repositories themselves? Preferably in such a way that this can be repeated easy, as soon as something changes. The target should be a read-only "flat" version of the same overall code. No merging should be necessary.

If this is possible, it would solve my Launchpad problems where bzr can import only repositories without submodules.


Solution

  • If you want to start with submodules' files but not as git repos, simply do the following:

    • clone recursively git clone --recursive [email protected]:homer/powerplant.git (insane repo name btw)
    • then un-register the submodule with git config --remove-section submodule.name

    You'll end up with what you want, submodule files in the working tree but submodules not initialized as such.

    You could have used the newest git submodule deinit command, but it also removes submodule's files from the working tree.