Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
`git submodule` Tips #git #submodule

git submodule Tips

To clone a repo with submodules

git clone --recursive git@github.com:url_to/awesome_submodule.git path_to_awesome_submodule

Add a submodule clone into an existing repo

git submodule add git@github.com:url_to/awesome_submodule.git path_to_awesome_submodule

If repo with a submodule that is empty

git submodule init

… or to fetch all submodules, even if not initialized yet, and recursively in case submodules have submodules

git submodule update --init --recursive

Grab update inside a single submodule

cd path/to/module
git fetch
git checkout -q <commit-sha1>
cd -
git commit -am “Updated submodule X to: blah blah”

To always see submodule status with git status while a repo

Status, like logs and diffs, is limited to the active repo (right now, the container), not to submodules, which are nested repos. This is often problematic (it’s super easy to miss a regression when limited to this view), so I recommend you set up a submodule-aware status once and for all:

git config status.submoduleSummary true

Useful global .gitcoinfig configurations

git config --global fetch.recurseSubmodules = on-demand # default for git 1.7.5+, but just in case
git config --global diff.submodule log # clearer container diffs when referenced submodule commits changed
git config --global status.submoduleSummary true # git status is useful again when a referenced submodule commit changed

…and aliases

git config --global alias.spull '!git pull && git submodule sync --recursive && git submodule update --init --recursive'
git config --global alias.spush 'push --recurse-submodules=on-demand'

more info

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.