yasith
yasith

Reputation: 9511

Converting cloned git repositories into submodules

I have a project which is a git repository, and inside that project I have some cloned git repositories.

The directory structure is like this.

main-project
    -other_project (cloned git repository)
    -another_project (cloned git repository)

When I tried to clone main-project into another system, it only has empty directories for other_project and another_project.

I know that I should have used git submodule to add those repositories in the first place. Since I didn't, is there any way to fix the mess I've made ?

There are about 15 repositories inside (which should be submodules), so a way to "bulk convert" all those repositories into submodules would be greatly appreciated.

Upvotes: 2

Views: 150

Answers (2)

naught101
naught101

Reputation: 19563

You can also just do git submodule add ./path/to/subdirectory ./path/to/subdirectory, which will add the repositories as submodules, but with the incorrect origin url. You can then manually edit .git/config and replace the urls with the correct urls (i.e. the ones you cloned from).

Upvotes: 1

VonC
VonC

Reputation: 1328152

You would need to create a script, a bit like in "How to do a bash foreach csv field to 'git submodule add'", except, for each nested repo, you would need to extract the upstream repo url (git remote origin)

Then add the .gitmodules file created in your parent repo by those "submodule add", and commit.

You will be able to clone (with --recursive option) your parent repo, and get back all those submodules.

Upvotes: 1

Related Questions