Skip to content

Instantly share code, notes, and snippets.

@Voronenko
Created January 3, 2014 18:22
Show Gist options
  • Save Voronenko/8243339 to your computer and use it in GitHub Desktop.
Save Voronenko/8243339 to your computer and use it in GitHub Desktop.
This shell file can be used to re-checkout git submodules basing on .gitmodules file
#!/bin/bash
git config -f .gitmodules --get-regexp '^submodule\..*\.path$' > tempfile
while read -u 3 path_key path
do
url_key=$(echo $path_key | sed 's/\.path/.url/')
url=$(git config -f .gitmodules --get "$url_key")
read -p "Are you sure you want to delete $path and re-initialize as a new submodule? " yn
case $yn in
[Yy]* ) rm -rf $path; git rm -r $path; git submodule add -b master $url $path; echo "$path has been initialized";;
[Nn]* ) exit;;
* ) echo "Please answer yes or no.";;
esac
done 3<tempfile
rm tempfile
git submodule init
git submodule update
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment