SeattleOrBayArea
SeattleOrBayArea

Reputation: 3118

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.

Upvotes: 23

Views: 26630

Answers (3)

Simon E.
Simon E.

Reputation: 58460

I also received this error using TortoiseGit while trying to update submodules that aren't in the index. That is, they exist in .gitmodules but have not been correctly added to the repository.

The solution is to manually re-add them using the paths specified in .gitmodules. You can use the TortoiseGit UI or run this on the command line for each module...

git submodule add <url> <path>

Re-adding a git submodule

(I realise this is probably not the solution for the original poster, but hopefully it helps others Googling this.)

Upvotes: 42

Highway of Life
Highway of Life

Reputation: 24321

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.

Upvotes: 9

Aasmund Eldhuset
Aasmund Eldhuset

Reputation: 37940

In order to get new submodules into other repositories, I believe you need to run git submodule init once before starting to run git submodule update; this will register the new submodule from .gitmodules in .git/config.

Upvotes: 2

Related Questions