Skip to content

Instantly share code, notes, and snippets.

@dingmingxin
Forked from aroemen/restore-git-submodules.sh
Created August 15, 2018 08:28
Show Gist options
  • Save dingmingxin/c5902494265b17298d152013d77aaa90 to your computer and use it in GitHub Desktop.
Save dingmingxin/c5902494265b17298d152013d77aaa90 to your computer and use it in GitHub Desktop.
Restore git submodules from .gitmodules. Since git submodule init only considers submodules that already are in the index (i.e. "staged") for initialization this short script parses .gitmodules, and each url and path pair.
#!/bin/sh
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment