What are the best practices for un-submoduling a Git submodule, bringing all the code back into the core repository?
What are the best practices for un-submoduling a Git submodule, bringing all the code back into the core repository?
Based on VonC's answer, I have created a simple bash script that does this. The add at the end has to use wildcards otherwise it will undo the previous rm for the submodule itself. It's important to add the contents of the submodule directory, and not to name the directory itself in the add command.
In a file called git-integrate-submodule:
#!/usr/bin/env bash
mv "$1" "${1}_"
git submodule deinit "$1"
git rm "$1"
mv "${1}_" "$1"
git add "$1/**"
In main repo
In submodules repo
Again main repo
Here's what I found best & simplest.
In submodule repo, from HEAD you want to merge into main repo:
git checkout -b "mergeMe"mkdir "foo/bar/myLib/" (identical path as where you want the files on main repo)git mv * "foo/bar/myLib/" (move all into path)git commit -m "ready to merge into main"Back in main repo after removing the submodule and clearing the path "foo/bar/myLib":
git merge --allow-unrelated-histories SubmoduleOriginRemote/mergeMeboom done
histories preserved
no worries
Note this nearly identical to some other answers. But this assumes you own submodule repo. Also this makes it easy to get future upstream changes for submodule.