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

`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.

All Git & GitHub questions Roadmap: Git & GitHub

More on Submodules, LFS and Hooks