hl037_
hl037_

Reputation: 3907

How to transform a directory of git repositories to one repository containing submodules?

Today, I have a directory containing several git repositories. Up to now, I could live with it because the repositories were quite distinct and unrelated. But now, I would like to make a "distribution" (not a linux one...) of these repositories with specific commits.

The natural solution feels to transform these repos to submodules, and have the parent directory as a "parent / main repo".

But is there any way to do this automatically, rather than adding submodules one by one by hand ?

Upvotes: 0

Views: 57

Answers (1)

torek
torek

Reputation: 489628

But is there any way to do this automatically, rather than adding submodules one by one by hand?

Write a bit of script to loop, adding submodules one by one:

git init  # you can do this by hand, it's just the one init

then the loop:

for dir in <list>; do git submodule add $dir; done

Your superproject is now ready for its first commit. As hl037_ noted in comments, a:

git submodule absorbgitdirs

is probably a reasonable thing to do at the end, and replacing git submodule add path with the longer git submodule add -- repository path can help out in some cases, especially when there's a remote repository name to use.

Upvotes: 2

Related Questions