0

I have two github repository similar to the below structure as an example:

repo1: [folder_X] fileA fileB fileC fileD [folder_Y] fileE fileF

repo2: [folder_M] fileB fileC fileK [folder_N] fileO fileP

as you see in both repository we have some common files in folder_X and folder_M which are fileB and fileC. I need to have a common source for these files, so I don't need to modify them in two repository always. These common files (B and C) can be stored in a separate branch in repo1 as an example.

Is there any solution for it without modifying the repo structure?

1 Answer 1

1

If you insist on using git submodules, then note that it works on a repository basis, i.e. you can only attach the full repository tree as a subfolder of another repository. You can't filter it, i.e. you get the full repository from the root folder with all the files and subfolders. Thus a clean way would be to create a repo3 with common files, and link it as a submodule to repo1 and repo2.

Another possible way is if you treat repo1 as a provider of common files, and repo2 as a derivative project (consumer). Then you can link repo1 as a submodule of repo2, and then modify the repo2 to reference files inside repo1 subfolder. This can be either a modification of project files or build scripts, or just symlinks.

A third way is to not use git submodules, but use some package manager. For example, some package managers support creating a package with just a few files out of a repository, and then you can reuse that package from another repo.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.