Git Submodules: Clone, Push All Submodules Automatically, and Remove.

Right after cloning the project, init the submodule with:

git submodule update --init

Then (if you need), go to that submodule’s folder and checkout to the branch.

Pushing Submodules Commit From Root Project

When pushing from root git, and git submodule actually have several commit to push too, the git root actually wont push with following error message:

Pushing submodule 'orig/natural-theme'
Everything up-to-date
The following submodule paths contain changes that can
not be found on any remote:
  orig/natural-theme

Please try

        git push --recurse-submodules=on-demand

or cd to the path and use

        git push

to push them to a remote.

fatal: Aborting.
fatal: the remote end hung up unexpectedly
remote: 
remote: ========================================================================
remote: 
remote: ERROR: user canceled the push

remote: 
remote: ========================================================================
remote: 

According to this Stackoverflow answer, both submodule and root repo should be in the same branch name. This is not written strictly in the documentation.

Deleting Submodule

Just run:

git rm <path-to-submodule>

Disclaimer:

Not all articles here are meant to be correct. My notes might be wrong or may no longer be relevant. If you want to try things here, please proceed with caution.


Posted

in

by

Tags: