Skip to content

Instantly share code, notes, and snippets.

@det-peralta
Forked from aroemen/restore-git-submodules.sh
Created November 25, 2019 16:18
Show Gist options
  • Save det-peralta/b903fa237b60248052c70e57273c40dc to your computer and use it in GitHub Desktop.
Save det-peralta/b903fa237b60248052c70e57273c40dc 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