When working with projects that have dependencies on other projects using git submodules can be really useful. It allows you to basically add links to other git projects inside your source code, without having to add all of the code of the project until you need it.

However, managing those git submodules (from .gitmodules) can prove to be a challenge. I reguarly ship software projects to new developers with multiple submodule and this handy little script will open each of the submodule exactly where you want them without having to use multiple git submodule add... commands.

#!/bin/sh
# This script will add all submodules from just a .gitmodules file
#

set -e

git config -f .gitmodules --get-regexp '^submodule\..*\.path$' |
    while read path_key path
    do
        url_key=$(echo $path_key | sed 's/\.path/.url/')
        url=$(git config -f .gitmodules --get "$url_key")
        git submodule add $url $path
    done

Personally, I use this inside a whole bunch of Ansible projects rather than using Ansible Galaxy but also use it to include files from other projects inside Docker containers.