How can I pull submodule commits from a central repository, without pushing the submodule commits to the submodule's upstream repository?
For example, let's say I have a central git repository A
which I clone:
git clone /path/to/A myA1
Now I add some repository, which I don't own, as a submodule:
git submodule add https://.../B.git myB
git commit -m "Added B submodule"
I add some changes to the B
submodule and commit them:
cd myB
echo foo >> x.txt
git add x.txt
git commit -m "changes in local B"
cd -
git commit -m "changes in submodule"
git push # push commits in local myA1 to central repo A
But I can't push the commits in myB
upstream to B
, because I can't write to B
(it's some repository on Github). When my coworkers clone the central repository A
, their submodule refers to the upstream B
repository, not the one in A
:
git clone /path/to/A myA2
Their url
entry in .gitmodules
points to https://.../B.git
, which doesn't contain my commit changes.
How can they pull the changes I committed to my B
submodule?
How can they pull the changes I committed to my B submodule?
You can't. If you want to make changes to the submodule, you'll need to host a fork of that repository someplace to which you can push changes. Then when you add the submodule, you would use your repository url rather than the upstream repository:
git submodule add https://new.repository.host/B.git myB
Typically, for GitHub hosted repositories, you would just fork the repository and then use that.
You will probably want to regularly rebase your own changes on the upstream repository in order to incorporate any upstream changes.