DO NOT COPY PASTE THIS WHOLE SCRIPT WITHOUT READING IT
YOU NEED TO MAKE VARIOUS ADJUSTMENTS. EXECUTE THESE COMMANDS STEP BY STEP!!
cd ~
mkdir -p repo-merge-directory && cd repo-merge-directory
git clone submodule.git submodule
cd submodule
git remote rm origin
The new path should be the path you used the submodule in your actual repo (replace "submodule_path")
git filter-branch --tree-filter \
'shopt -s dotglob nullglob extglob; mkdir -p ../tmp; mv * ../tmp; mkdir -p submodule_path; mv ../tmp/* submodule_path/' \
--tag-name-filter cat --prune-empty -- --all
git gc
cd ~/repo-merge-directory
git clone repo.git repo
cd ~/repo-merge-directory/repo
git remote rm origin
This is where you saved the submodule (replace "submodule_path")
git filter-branch --force --index-filter \
'git rm --cached --ignore-unmatch -r submodule_path' \
--prune-empty --tag-name-filter cat -- --all
git gc
git remote add submodule ~/repo-merge-directory/submodule
git pull submodule master --allow-unrelated-histories
This is very distructive to existing repositories. Never, for the love of god, use force push.
git remote add origin new_repo.git
git push -u origin master
❤️