What are the best practices for un-submoduling a Git submodule, bringing all the code back into the core repository?
If all you want is to put your submodule code into the main repository, you just need to remove the submodule and re-add the files into the main repo:
git rm --cached submodule_path # delete reference to submodule HEAD (no trailing slash)
git rm .gitmodules # if you have more than one submodules,
# you need to edit this file instead of deleting!
rm -rf submodule_path/.git # make sure you have backup!!
git add submodule_path # will add files instead of commit reference
git commit -m "remove submodule"
If you also want to preserve the history of the submodule, you can do a small trick: "merge" the submodule into the main repository so that the result will be the same as it was before, except that the submodule files are now in the main repository.
In the main module you will need to do the following:
# Fetch the submodule commits into the main repository
git remote add submodule_origin git://url/to/submodule/origin
git fetch submodule_origin
# Start a fake merge (won't change any files, won't commit anything)
git merge -s ours --no-commit submodule_origin/master
# Do the same as in the first solution
git rm --cached submodule_path # delete reference to submodule HEAD
git rm .gitmodules # if you have more than one submodules,
# you need to edit this file instead of deleting!
rm -rf submodule_path/.git # make sure you have backup!!
git add submodule_path # will add files instead of commit reference
# Commit and cleanup
git commit -m "removed submodule"
git remote rm submodule_origin
The resulting repository will look a bit weird: there will be more than one initial commit. But it won't cause any problems for git.
In this second solution you will have the big advantage that you can still run git blame or git log on the files which were originally in submodules. In fact what you did here is to rename many files inside one repository, and git should autodetect this. If you still have problems with git log, try some options (--follow, -M, -C) which do better rename/copy detection.