Git submodule from subdirectory?

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

  • How to store my password and login for my remote repository?
  • Puppet agent: provider git is not functional on this host
  • Git did not push correctly after rewriting history
  • How does the github website work (architecture)?
  • When should I use git pull --rebase?
  • OSX: git: remote: Permission to user/repo denied to otheruser
  • 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.

  • Git: unable to redirect/parse the output of 'git fetch --dry-run' command
  • git shows many changes in repository after moving project folder
  • Difference between checkout remote branch and pull remote branch in git?
  • Platform-specific git configuration files
  • Cloning specific branch
  • GitHub API - write to repo
  • One Solution collect form web for “Git submodule from subdirectory?”

    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.

    Git Baby is a git and github fan, let's start git clone.