`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.`
IntermediateTroubleshootingSubmodules, LFS and Hooks
Answer
Likely causes → The superproject points at a submodule commit that does not exist on the submodule's remote. Someone committed the new gitlink but never pushed the submodule commit, or the submodule branch was force-pushed and the commit is gone.
Diagnose →
git ls-tree HEAD libs/common # commit the parent expects
git -C libs/common branch -r --contains 3f2a9c1
git log -1 --format='%an %ae' -- libs/common # who bumped it
Fix → Ask the author to push the submodule commit (git -C libs/common push origin HEAD:main). If it is lost, point the gitlink at a commit that exists and commit that: git -C libs/common checkout <good-sha> && git add libs/common && git commit.
Prevent → Set git config --global push.recurseSubmodules check (or on-demand) so pushing the parent fails if submodule commits are not on a remote.
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 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`.IntermediateRe-adding a removed submodule fails: `A git directory for 'libs/common' is found locally with remote(s): origin https://github.com/org/common.git`.Advanced