Skip to content

Instantly share code, notes, and snippets.

@dnedrow
Created May 19, 2022 23:18
Show Gist options
  • Select an option

  • Save dnedrow/93915314a15c8a0ce22a16ae792ac134 to your computer and use it in GitHub Desktop.

Select an option

Save dnedrow/93915314a15c8a0ce22a16ae792ac134 to your computer and use it in GitHub Desktop.
This script will add all submodules from just a .gitmodules file
#!/bin/sh
# This script will add all submodules from just a .gitmodules file
#
# This script copied from https://www.willhallonline.co.uk/blog/2019-03-05-scripting-adding-gitmodules/
# One addition is the '--force' directive on 'submodule add'.
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 --force $url $path
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment