I tried deleting a submodule and then adding it back with git 1.8.5.2.
An submodule asub
was added by git submodule add -b master url_asub.git
.
I removed the submodule by
git rm asub
The asub directory is gone. I then tried to add it back again with the original command that added it (to test if the submodule removal in 1.8.5.2 is clean):
git submodule add -b master url_asub.git
I got an error message:
A git directory for 'asub' is found locally with remote(s):
origin url_asub.git
If you want to reuse this local git directory instead of cloning again from
url_asub.git
use the '--force' option. If the local git directory is not the
correct repo or you are unsure what this means choose another name with the
'--name' option.
I am not sure what this error message means. I also tried doing git submodule sync
in the superproject, and tried
git submodule deinit asub
git rm asub
git submodule add -b master url_asub.git
But still I couldn't add the submodule back. What did I miss, or is this a bug in git 1.8.5.2?
The reason I want to do this is to a) remove a submodule and b) add it back so that it reflects the most recent content of the submodule. This may sound naive but I found that the submodule add -b
feature will break as soon as I clone the super project (how to keep git submodule on-branch status after cloning superproject?). So I figured probably a simply way to avoid all the troubles of keeping submodules tracking their master branches is to remove the submodule and add it back every time when cloning the super project.