Git submodules

Include submodules when cloning the parent repository: git clone --recursive URL.

Pull main repo including submodules: git pull --recurse-submodules

Pull changes for submodule: git submodule update --remote

Docs on the --remote flag: "This option is only valid for the update command. Instead of using the superproject’s recorded SHA-1 to update the submodule, use the status of the submodule’s remote-tracking branch."

Is the --remote flag really necessary? When I want to pull in changes from the submodule and register in the parent git module that the submodule has changed, then yes.

A side-effect I noticed is that the HEAD gets detached using the above command. This should not happen if you specify --merge or --rebase: git submodule update --remote --merge. You can specify this behavior in the .gitmodule instead (see below).

Add a submodule and initialize the submodule configuration file:

git submodule add URL
git submodule init

Gotcha: Personal Access Tokens can only be used over https.

This is an example of a .gitmodules file I use:

[submodule "content/zettelkasten"]
    path = content/zettelkasten
    url = https://github.com/EdwinWenink/Notes.git
    #url = git@github.com:EdwinWenink/Notes.git
    update = merge  # prevents detached HEAD

The commented out line is the remote submodule URL over ssh connection, which I had to change to https (see line above)

Gotcha: after changing to https I still had the same issue. I observed that despite the changed .gitmodules file, the ssh connection was still being used.

Solution: it is apparently needed to manually sync the updates settings to your .git/config with git submodule sync.