1

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.

amira
  • 416
  • 1
  • 7
  • 24

1 Answers1

1

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?".

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 1
    Oh yeah, this is what I am looking for. I will try it out and let you know. Thanks @VonC – amira Aug 10 '22 at 05:52
  • I tried this solution and worked like a charm. In the `settings.gradle` folder don't forget to include the module and provide a path as described in this SO post: https://stackoverflow.com/questions/28658574/android-studio-how-to-make-modules-inside-a-subdirectory – amira Aug 12 '22 at 20:15
  • 1
    @amira Great, well done! I have included your comment in the answer for more visibility. – VonC Aug 12 '22 at 20:28