As in jthill answer, you can add any item from subdirectory with .git
and it will be treated as subdirectory instead of sub-module.
But if you already registered this subdirectory as sub-module that has .git
you have to first remove that sub-module but leave it in your working tree - git rm --cached a/submodule
.
More info on: How do I remove a submodule?
Then you can repeat steps from jthill answer.
From my research there is no way to stop treating .git
folder as sub-module. So the best solution that I can think of right now is to have bash
or any similar script that you can run in any folder in console. It should find any subfolders that have .git
and attempt to add any file from that folder to the main .git
, so it would stop treating them as sub-modules.
Source of code below: Bash script to automatically convert git submodules to regular files
#!/bin/bash
# Get a list of all the submodules
submodules=($(git config --file .gitmodules --get-regexp path | awk '{ print $2 }'))
# Loop over submodules and convert to regular files
for submodule in "${submodules[@]}"
do
echo "Removing $submodule"
git rm --cached $submodule # Delete references to submodule HEAD
rm -rf $submodule/.git* # Remove submodule .git references to prevent confusion from main repo
git add $submodule # Add the left over files from the submodule to the main repo
git commit -m "Converting submodule $submodule to regular files" # Commit the new regular files!
done
# Finally remove the submodule mapping
git rm.gitmodules
Remember to always commit/backup changes before trying new scripts to prevent any work/data loss.