MeLight
MeLight

Reputation: 5565

Common code between two projects (repos?)

I know this has been asked in one way or another before, but I haven't found an answer which would answer my problem.

I have a two codebases A and B (aimed at different platforms) sharing most of their code. Let's call the shared code part C.

What I'd like to do is have a repo(s?) setup in a way that I can commit changes to part C from A, and then pulling B will get me the changes I made to C residing in A and the other way around.

For example, consider this dir structure:

A
|
|-- a.txt
|-- common.txt

B
|
|-- b.txt
|-- common.txt

If I make changes to A/common.txt and then pull B I want the changes I made to A/common.txt to be present in B/common.txt

Thanks

Upvotes: 2

Views: 148

Answers (2)

Bob Gilmore
Bob Gilmore

Reputation: 13758

"Submodules" in git were designed for this (among other things). In your case, all of the "common" files would live in a subdirectory structure "inside" the "main" projects. Then, that common directory structure would be a "submodule" that both "main" repos maintain references to.

See, for example, this documentation on creating and using submodules.

Upvotes: 1

bredikhin
bredikhin

Reputation: 9025

You should consider using Git submodules.

The only thing to mention, probably, is that you would be better off making changes in a completely different folder, then pushing the commits to the server and, finally, pulling from your code bases as submodules.

Upvotes: 1

Related Questions