8

Let's say I have two git repos. RepoA is a common repo that should be shared among other projects. ReopB is some project that needs to access something in RepoA.

RepoA

https://.../RepoA
    /Something
    /Source
        /Project1
        /Project2
        ...
        /ProjectN

RepoB

https://.../RepoB
    /SomethingElse
    /Source
        /MainProject
        /RepoA
            /Project1  #Submodule of RepoA at /Source/Project1

Using the illustration above, you can see what I am trying to do is configure a submodule that is not the root of RepoA, but a specific path within the repo. In this case, I want to map RepoB/Source/RepoA/Project1 to RepoA/Source/Project1.

I've done some research and it seems that it is not straightforward, or perhaps not possible to do this. I hope I'm wrong!

We're moving from SVN to GIT and in SVN we were using Externals to accomplish this with ease.

Note

I am also open to restructuring RepoA. But I want to keep the main structure in place. For instance, if I can somehow branch each Project within RepoA/Source/...but I don't want this to get complex.

alroc
  • 27,574
  • 6
  • 51
  • 97
Josh M.
  • 26,437
  • 24
  • 119
  • 200
  • possible duplicate of [Merge git repository in subdirectory](http://stackoverflow.com/questions/6426247/merge-git-repository-in-subdirectory) – oyvind Jul 18 '14 at 23:27
  • Have a look at http://stackoverflow.com/questions/6426247/merge-git-repository-in-subdirectory – oyvind Jul 18 '14 at 23:28

2 Answers2

3

Have you considered splitting up the 'Projects' in RepoA such that they are separate repos? You could do this by using git subtree split. Then you include the Project1 repo as submodules in both RepoA and RepoB.

Community
  • 1
  • 1
ma499
  • 601
  • 4
  • 13
  • Yes, I think that is what I'll have to do. I was hoping to NOT have to do that. Will look into it - thanks. – Josh M. Jul 21 '14 at 18:03
0

The way out I get for this issue is to split into branches each directory that is expected to create a submodule from it. In your example, we create a branch named "branch-Project1" and put all the contents of the directory Project1 in this new branch.

Then, on RepoB we run

git submodule add -b branch-Project1 https://github.com/<user-name>/RepoA path/to/submodule

This will create a submdule located at path/to/submodule in RepoB.

Rubem Pacelli
  • 332
  • 2
  • 12