Skip to content

Instantly share code, notes, and snippets.

@ygorth
Forked from aroemen/restore-git-submodules.sh
Created November 28, 2017 20:32
Show Gist options
  • Save ygorth/2463f38bb5d735f406cb4a974bd21abc to your computer and use it in GitHub Desktop.
Save ygorth/2463f38bb5d735f406cb4a974bd21abc 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