To remove the “leftover” submodules after checking out a different branch, you can run the following. This command will recursively clean the main repository and all submodules.Warning: this will remove all untracked files as well.
git clean -xffd && git submodule foreach --recursive git clean -xffd
To see which files will be deleted without actually deleting yet, add the -n flag.
git clean -nxffd && git submodule foreach --recursive git clean -nxffd