How can I add a git submodule with the same name as an old, deleted git directory?

directory, git, git-submodules, local

Solution

Make sure you have first remove and committed the '`built`' folder.

git rm -rf built
# or, if built isn't in the working tree
git rm --cached -rf built
git add -A
git commit -m "remove built"

Then you can try your `git submodule add`.

Problem

I'm trying to turn a directory into a submodule and effectively turn the thing into a git superproject/project with specialized submodules inside. I have a "built" directory (necessary for what I'm making, as some of the dependencies are closed-source and therefore not in the git repo, meaning that some people can't build their own version), but I want to turn it into a separate repo placed in the same location as before. That is, instead of being `/built` as a directory tracked by the repo, I want it to be `/built` as a submodule tracked by a different repo. However, when I try deleting `/built`, committing that, and executing `git submodule add BUILT_REPO_URL built`, I get: ``` A git directory for 'built' is found locally with remote(s): origin BUILT_REPO_URL If you want to reuse this local git directory instead of cloning again from BUILT_REPO_URL 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 have substituted BUILT_REPO_URL for the appropriate git repository hosting URL.) I don't want to rename the directory because that seems odd and I have build scripts and whatnot that I'd have to change. Besides, there are other directories I want to do this to as well, and they have a fairly set directory structure based on the framework I'm using. I've tried removing files from the cache (didn't have them there) and other similar steps. The problem is also un-Googleable, since all the results I've found have been for changing a submodule to a different submodule with the same directory name.

Original source