Git

Git Submodule Life-Saving Setup

What’s the use of git submodules? It’s mostly useful when you want to work on the code in both the main repo and the sub repo at the same time. Otherwise, a normal dependency management system would suffice.

To have submodules safely set up so that you run into walls less often, do the following:

  • Automatically log submodule changes when git diffing, to prevent you from committing changes you didn’t want to commit:
git config --global diff.submodule log
  • To display a short summary of changes to submodules when using git status:
git config --global status.submodulesummary 1
  • Before main repo changes are pushed, make sure submodule changes are pushed first, so that you don’t forget to publish dependencies:
# two options:

$ git config --global push.recurseSubmodules check # prompt you to push submodule changes yourself
$ git config --global push.recurseSubmodules on-demand # automatically push submodule changes for you

That’s it! Safe sub-moduling. 😀

Standard

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.