Search code examples
gitgit-submodulesgit-subtree

Project dependent on other project from multiple sources


So I have a project A, which uses project B. So I went ahead and marked B as a subtree for the project A and merged the changes from B into A time to time. Also there is a project that I want to use called C, C is also a subtree of the project B. But what I would like to do is add C as a subtree independently in my project and also not have 2 copies of the codebase of C in the project A. How can I go about solving this ? Any help will be appreciated. Thanks.


Solution

  • The problem with subtree is that C is part of B history.

    If you can reference a B without C as a subtree, then you can go the submodule route:

    • add C as a submodule to A
    • add C as a submodule to B
    • make sure A and B references the same C SHA1
    • update only the C from A (git submodule update) in order to get only one C source.

    The idea is to:

    • keep two references to C (in order to detect a possible discrepancy between the C used by A and the one used by B)
    • update only one of the two C submodules.