JUAN CALVOPINA M
JUAN CALVOPINA M

Reputation: 3984

Create a repository with sub-repositories

I want to create a repo that has sub-repositories, to do that I created a sample folder in my workspace:

$ cd ~/workspace/
$ mkdir samples
$ cd samples
$ pwd
~/workspace/samples

This means that the sample folder will be the main repository (something like a container), for example I would like to have the following structure:

$ mkdir sample-java
$ mkdir sample-c-plus-plus
$ mkdir sample-csharp
$ ls -l
total 3
drwxr-xr-x  juanca  staff  408 Mar 30 20:04 sample-java
drwxr-xr-x  juanca  staff  408 Mar 30 20:12 sample-c-plus-plus
drwxr-xr-x  juanca  staff  408 Mar 30 20:23 sample-csharp

I want a repo for each folder listed above, in my github account, for example:

|- samples -----------------> github.com/my-user/samples.git
    |- sample-java ---------> github.com/my-user/samples.git/sample-java.git
    |- sample-c-plus-plus --> github.com/my-user/samples.git/sample-c-plus-plus.git
    |- sample-csharp -------> github.com/my-user/samples.git/sample-csharp.git

I would like to have control in each sample-* folder and in turn all of them grouped in a main repository.

Is it possible? Or what would be the best approach?

I found something similar with git submodule, but this adds an existing repo, for example:

$ git submodule add https:// github.com/any-account/any-project.git any-project

I do not think this solution works for me. Any idea?

Upvotes: 5

Views: 1948

Answers (1)

VonC
VonC

Reputation: 1328712

I found something similar with git submodule, but this adds an existing repo.

This is actually the solution.

Each of your sub-repo should be individual repos of their own (ie, directly under github.com/my-user).
That way, you can declare them as submodule of your main repo

cd samples
git submodule add github.com/my-user/sample-java.git sample-java
git submodule add github.com/my-user/sample-c-plus-plusgit sample-c-plus-plus
git submodule add github.com/my-user/csharp.git sample-csharp

That way:

  • any git clone --recursive of the repo samples would automatically clone and checkout those sub-repos at their respective SHA1.
  • any modification done in each repo can be tracked indivisually, added and committed (and pushed) to its own repo.

Upvotes: 4

Related Questions