Re-adding a removed submodule fails: `A git directory for 'libs/common' is found locally with remote(s): origin https://github.com/org/common.git`.
AdvancedTroubleshootingSubmodules, LFS and Hooks
Answer
Likely causes → Removing a submodule leaves its repository in .git/modules/libs/common. Git refuses to silently reuse it, in case it belongs to a different repo.
Diagnose →
ls .git/modules/libs/
git config -f .git/modules/libs/common/config remote.origin.url
Fix → If it is the same repo, reuse it: git submodule add --force https://github.com/org/common.git libs/common. If it is a different repo, delete the stale directory first: rm -rf .git/modules/libs/common, or pick another name with --name.
Prevent → Remove submodules completely:
git submodule deinit -f libs/common
git rm -f libs/common
rm -rf .git/modules/libs/common
More on Submodules, LFS and Hooks
`fatal: No url found for submodule path 'libs/common' in .gitmodules`IntermediateAfter cloning, the submodule directories exist but are empty.Beginner`git submodule update` fails: `fatal: remote error: upload-pack: not our ref 3f2a9c1...` and `Fetched in submodule path 'libs/common', but it did not contain 3f2a9c1. Direct fetching of that commit failed.`Intermediate`git status` keeps showing `modified: libs/common (new commits)` even though you never touched it.BeginnerYou committed inside a submodule, ran `git submodule update`, and your commits vanished.Intermediate`git submodule add` fails with `fatal: 'libs/common' already exists in the index`.Intermediate