Search code examples
gitgit-submodules

git submodule update fails with error on one machine but works on another machine


I created a git submodule and pushed it onto our main repository. This worked fine and I can see the submodule in the repository via a browser.

To test it I tried to get the source in a fresh build tree. First I ran git submodule init and then git submodule update <submodule-name>.

The second command failed with error:

error: pathspec 'x/mypkg' did not match any file(s) known to git. Did you forget to 'git add'

I tried adding to .gitmodules the url to the submodule but with no luck.


Solution

  • This is likely because you or someone on your team has changes in your submodule that are unpublished (committed, but not pushed to the remote server). They then published the superproject with references to the git commit in the submodule which does not exist on the git server. So git is trying to pull down a specific submodule git commit ID that it can't find.

    This would be the case if the changes are in a repository elsewhere on your machine or on another machine.

    To resolve, go to that repository that references that commit and publish (push) the submodule changes to the server. Or change the submodule to point to a different commit ID.