Home > database >  Two unmerged repositories inside one project
Two unmerged repositories inside one project

Time:08-13

I have a project that uses modules. One of the modules that I need to use is inside another repository. In the future, I will connect that module into my project using mavenCentral, but not now.

I want to have my MODULE from another repository inside my PROJECT without adding the MODULE into my PROJECT GIT. And I should be able to switch between git repos and commit the changes into their corresponding repositories.

So far I did this:

-- added MODULE origin inside PROJECT like so.

git remote add MODULE [module URL in Github]
git fetch MODULE

after the above steps, when I do git remote -v it is displaying two remotes. One for PROJECT (origin) and one for MODULE.

After these steps, I am not sure what to do next in order to achieve my objective. Is it even possible?

I tried git merge MODULE/master --allow-unrelated-histories but it is adding my MODULE code into my PROJECT which I don't want.

Could someone point me in the right direction? Thanks.

CodePudding user response:

It would be easier to use git submodule for that kind of use.

Your parent repository would keep a reference on your MODULE repository in a MODULE subfolder, but any change done on that subfolder can be pushed directly to the remote MODULE repository.

cd /path/to/repo
git submodule add [module URL]
cd module
# work on module, add, push, commit
cd ..
git add module
git commit -m "reference new module state"

The OP amira confirms in the comments:

Worked like a charm.
In the settings.gradle folder, don't forget to include the module and provide a path as described in "Android Studio - How to make modules inside a subdirectory?".

  • Related