Search code examples
gitgit-submodulesgit-subtree

git subtree or submodule for surrounding directories


We commonly work on projects that share a similar directory structure to CodeIgniter, where there is a framework surrounding our application code (in parent and sibling directories). We have two main workflows that we need to manage:

  1. maintain our local application code (e.g. the /application directory) in a private (non-github) repository
  2. pull upstream changes from the outer framework, submit pull requests, etc.

The closest approach I've found in my research would be to use fake submodules, with a dash of .gitignore or some sort of related voodoo, however that seems very fragile. Is there a better approach to setting up our repositories and directories?


Solution

  • The better approach is to invest the time in the learning curve of (non-fake) submodules or subtrees, in that order of preference. You are right in your assessment - the "fake submodules" are a fragile attempt to over-simplify, and such will suffice in the trivial cases, but won't be suitable with many projects and multiple collaborators with different ideas on the branching, history and release management of the subprojects.

    If you do want to treat everything as one huge project you could look into git subtree merges, but I would advise against that in your case, as submodules are especially suitable for managing 3rd part dependencies with different release schedules.

    From your question I understand that your setup looks like this, simplified,

    parent-framework
    |-- application
    |-- framework
    `-- other-framework
    

    And where frameworks (ie., framework, other-framework and possibly parent-framework) are separate projects managed on github.

    So here's what I would do,

    1. Manage the application repository in a standalone private repo
    2. Fork the frameworks
    3. Create a superproject at or above the parent-framework level to tie everything together, where all the frameworks, including your private application repo are submodules.

    This will give you the necessary flexibility to manage your application development line SDLC with respect to the orthogonal SDLC of the 3rd-party dependency frameworks.

    Also notice that the recent versions of git make it significantly easy to recursively push (and update) submodules, so there should be little concern for the complexity of creating pull requests for the frameworks.