Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to use different apps as git submodules in a nx workspace?

Tags:

git

nrwl

nrwl-nx

I want to build a nestjs backend which is used by a angular frontend application. Each of them for now in a single repository. I stumbled over nrwl-nx for monorepo tooling and am really intrigued to use it.

But my question now is: is it possible to have different apps in the workspace, but each as an own git submodule? Like so:

workspace_folder
|- apps
|  |- application1 <--- git submodule 1
|  |- application2 <--- git submodule 2
|- libs
|...

How would the process be to set them up correctly? Can it be done completely by the nx CLI? I couldn't find anything specific to that in the nx documentation.

like image 638
Hüftl Avatar asked Mar 04 '20 12:03

Hüftl


People also ask

How does Git subtree work?

git subtree allows you to nest a repository as a subdirectory inside another. It's one of the various options for managing project dependencies in Git projects. You add a subtree to an existing repository where the subtree is a reference to another repository URL and branch/tag when you wish to utilize it.

What are Git submodules and why do we use them?

Why do we use Git submodules in the first place? In most cases, Git submodules are used when your project becomes more complex, and while your project depends on the main Git repository, you might want to keep their change history separate.

What is a gitmodules file?

This .gitmodules file is one of multiple places where Git keeps track of the submodules in our project. Another one is .git/config, which now ends like this: And finally, Git also keeps a copy of each submodule’s .git repository in an internal .git/modules folder. All of these are technical details you don’t have to remember.

How do I check for new changes in a submodule?

Checking for new changes in a submodule, for example, works like in any other Git repository: you run a git fetch command inside the submodule repository, possibly followed by something like git pull origin main if you want to indeed make use of the updates.

What happens if a submodule is not provided with a path?

If a path is not provided, the submodule will default to the same name as its repository. If we look into the House repository, we’ll see the subdirectory Room repository like so:


Video Answer


1 Answers

Yes! I believe you can do this using Yarn workspace in conjunction with Nx tooling.

So in essence you need to navigate to your apps folder and run:

  • git submodule add https://github.com/[URL for your application 1] application1
  • git submodule add https://github.com/[URL for your application 2] application2

More Details here: https://blog.nrwl.io/dev-workflow-using-git-submodules-and-yarn-workspaces-14fd06c07964

An example will be like this: https://github.com/nrwl/nx-example-multirepo

like image 127
Nico Avatar answered Oct 17 '22 02:10

Nico