You've successfully subscribed to MyPad Blog
Great! Next, complete checkout for full access to MyPad Blog
Welcome back! You've successfully signed in.
Success! Your account is fully activated, you now have access to all content.
Success! Your billing info is updated.
Billing info update failed.

Restore gitsubmodules from a previous project

Restore gitsubmodules from a previous project

Ever wanted to use a previous project to seed a new one?

We often have to do that. With re-using an existing project, we typically need to see our git repo with also the submodules that were used.

Here is a script that does just that!

#!/bin/sh
# credit: https://stackoverflow.com/questions/11258737/restore-git-submodules-from-gitmodules
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

Simply run it bash ./shell/restore-git-submodules-from-gitmodules.sh and all the submodules should be in the new repo!