Interview Prep/Git & GitHub/Submodules, LFS and Hooks

`git submodule add` fails with `fatal: 'libs/common' already exists in the index`.

IntermediateTroubleshootingSubmodules, LFS and Hooks
Answer

Likely causes → The path is already tracked, either as normal files (vendored copy) or as an old gitlink.

Diagnose → git ls-files -s libs/common | head (mode 100644 = files, 160000 = gitlink).

Fix →

git rm -r --cached libs/common
rm -rf libs/common
git commit -m "Remove vendored common"
git submodule add https://github.com/org/common.git libs/common

Prevent → When converting vendored code to a submodule, remove and commit the old files in a separate step first.

All Git & GitHub questions Roadmap: Git & GitHub

More on Submodules, LFS and Hooks