Search code examples
gitgit-submodules

How can I create a Git submodule with two locations?


I have the following project structure of which is want to move the marked* folders to a single git submodule, since they are dependent on each other. Is this possible in git?

main_project
|
|-backend
|  - backend_submodule*
|  - other
|
|-frontend
   - frontend_subodule*
   - other

Solution

  • If you're working on Linux or MacOS, you can always use symlinks. Have submodule mysubmodule under main_project contain backend and frontend. And then create the two symlinks with the names you want. To your build environment, it'll look like the directory structure you want, even if the actual git submodule is in just one directory.

    You can commit symlinks into a Git repo (and they'll work as long as you don't need to use this in Windows) so it's a one-time setup.

    main_project
    |
    |-mysubmodule
    |  -backend
    |  -frontend
    |
    |-backend
    |  - backend_submodule -> ../mysubmodule/backend
    |  - other
    |
    |-frontend
       - frontend_subodule -> ../mysubmodule/frontend
       - other