Reputation: 1587
I have a git project that contains a git submodule that I cloned from a public read-only repository (i.e. I cannot push to that repository). Is it possible to commit to that submodule? Here's how I tried to do this
[main]$ cd sub
[sub]$ git checkout master
[sub]$ echo test > new-file
[sub]$ git add new-file
[sub]$ git commit -m 'added a new file'
[sub]$ cd ..
[main]$ git add sub
[main]$ git push origin
So far so good. Now the problem is when I go to another computer and I do the following:
[main]$ git pull
[main]$ git submodule update
but it fails with fatal: reference is not a tree: af232...
. I thought that this would work because when I do git push origin
in main it seems that it pushes all objects for the submodules as well (after all they are in main's .git directory). But apparently, when the second computers pulls, it does not receive these new objects.
Upvotes: 2
Views: 205
Reputation: 90316
This is because you have pushed the submodule change in the super-project, but you have not pushed the actual change that happened in the submodule (git push origin
doesn't push submodule changes, only its commit SHA1.). This is not something you can do since it is a read-only repo.
What you can do is to change the URL of the submodule to a repository of your own, push the change to it, and commit and push the URL change in the super-project.
Upvotes: 1