I have a git repository with three submodules. The containing repository has two branches master
and develop
. All submodules only have one branch – the master
branch.
When the containing repository is on the master branch, pushing to origin via git push --recurse-submodules=on-demand
works as expected. Both the containing project as well as its submodules are pushed.
Now here is the problem. When the containing repository is on the develop
branch, I am getting a problem when pushing via git push --recurse-submodules=on-demand
. The push operation is cancelled and an error message is printed.
Here is the full output I get from git:
$ git push --recurse-submodules=on-demand
fatal: src refspec 'refs/heads/develop' must name a ref
fatal: process for submodule 'Frameworks/OpenLearnWareClient' failed
I can mitigate this problem by first pushing changes in each submodule manually and then pushing the containing repository. This however is very tedious and defeats the purpose of --recurse-submodules=on-demand
.
Here is my .gitmodules
file:
[submodule "Frameworks/OpenLearnWareKit"]
path = Frameworks/OpenLearnWareKit
url = [email protected]:kaiengelhardt/OpenLearnWareKit.git
branch = master
[submodule "Frameworks/OpenLearnWareClient"]
path = Frameworks/OpenLearnWareClient
url = [email protected]:kaiengelhardt/OpenLearnWareClient.git
branch = master
[submodule "Frameworks/KEFoundation"]
path = Frameworks/KEFoundation
url = [email protected]:kaiengelhardt/KEFoundation.git
branch = master
I am using git version 2.20.1 (Apple Git-117).
Does anybody know what is going wrong here and how to make recursive pushing work?
In order to add a Git submodule, use the “git submodule add” command and specify the URL of the Git remote repository to be included as a submodule. When adding a Git submodule, your submodule will be staged. As a consequence, you will need to commit your submodule by using the “git commit” command.
You can treat a submodule exactly like an ordinary repository. To propagate your changes upstream just commit and push as you would normally within that directory.
push third-party library to its central repository. add submodule in parent repo (make it aware of the new commit) and commit. push parent project to its central repo. parent's central repo hook checks out to your server, and updates submodule there.
git submodule sync synchronizes all submodules while git submodule sync -- A synchronizes submodule "A" only. If --recursive is specified, this command will recurse into the registered submodules, and sync any nested submodules within.
As far as I can tell (I’d like to be proved wrong!) there is no “recursive push” for submodule branches. In general, branches in submodules are an odd beast and don’t work the same way as regular branches in Git.
A close workaround is to use the git submodule foreach
command to perform the pushes. This is still annoying but at least it solves the “tedious” aspect. Combine the commands as follows to ensure that a failed submodule push aborts the parent module push:
git submodule foreach --recursive 'git push' &&
git push
As far as I can tell this is essentially equivalent to passing --recurse-submodules=on-demand
, but works with branches.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With