Home > front end >  How can in create a git submodule with two locations?
How can in create a git submodule with two locations?

Time:01-12

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

CodePudding user response:

No. A Git repository controls a folder and its subfolders. (The problem you describe is a common one, but you just have accept the common solution: the front end and the back end are different repos.)

CodePudding user response:

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 it's in one directory is the actual git submodule.

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

CodePudding user response:

For tightly-coupled histories like this, just carry them as independently-rooted branches in your main repo and git worktree add instead of going through the submodule helper. That way when you clone the main repo you've got everything, and you still have the separate histories that can be split out to separate repos elsewhere if the code's more widely useful.

  •  Tags:  
  • Related