Skip to content
This repository was archived by the owner on Nov 16, 2022. It is now read-only.

Git submodule notes

Kathy Walrath edited this page May 23, 2019 · 1 revision

Git submodule notes

Reference: https://git-scm.com/book/en/v2/Git-Tools-Submodules

One-time setup

Config

Ensure that submodule changes aren't lost when the main repo is pushed:

git config push.recurseSubmodules check

Workflow

Clone this repo and its submodule

git clone --recurse-submodules https://github.com/dart-lang/site-webdev.git

Pull upstream changes

After you fetch/pull site-www (e.g., a fresh clone of the main repo), also fetch/pull submodules

git submodule update --init --remote

Commit submodule changes

After editing files in the submodule, you need to do the following in the specified order:

  1. Commit and push submodule changes. See instructions below.
  2. Commit and push the main repo changes.

Commit and push using your favorite tools. To manually do so for the submodule, you can minimally execute the following commands:

$ cd site-shared
$ git commit -am "<Relevant commit message goes here>"
$ git push

You can also create a branch in the submodule and create a PR from the pushed branch, etc.

Other submodule actions

Adding a submodule / cloning for the first time

Cloning submodule for the first time:

$ git submodule add -f https://github.com/dart-lang/site-shared.git site-shared

During development, if you happen to switch branches without having committing the submodule config, then run:

$ if [ -d site-shared ]; then rmdir site-shared; fi  # won't do anything if the dir is non-empty
$ git submodule add -f https://github.com/dart-lang/site-shared.git site-shared

Miscellaneous notes

  • By default, Travis fetches submodules when it clones a repo.