1

I have a set of Git submodules to be included in multiple projects. I use TortoiseGit and adding them one by one to each new project is not convenient.

For example, in TortoiseSVN, one can simply export svn:externals to a file and then apply this file to a new project. I'm looking for something like that (I'd prefer to avoid scripting if possible).

What is my best bet in this case?

MrTux
  • 28,370
  • 24
  • 91
  • 123
Igor Melnichenko
  • 134
  • 1
  • 12
  • Cf. https://stackoverflow.com/q/11258737/3906760, I'm not marking this a duplicate as this is for TortoiseGit which might implement such a feature in the future. – MrTux Jan 25 '18 at 15:37

1 Answers1

2

Basically the TortoiseGit add submodule dialog is just a GUI frontend for git submodule add which basically is just a wrapper for the file .gitmodules in the root of the working tree.

I.e., you can consider automating the call of git submodule add or just write a .gitmodules by hand (or copy it from another repository) and then the submodules need to be registered (this cannot be done using TortoiseGit ATM):

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

Based on: https://gist.github.com/aroemen/5027030

MrTux
  • 28,370
  • 24
  • 91
  • 123