3

I have a git repository that is built with one library and during compiling the library is switched for another to get 2 versions of compiled code for 2 different libraries. (different versions of the same software)

This method has been working until now.

Now I have received a new 3rd library that differs significantly in some classes. I would like to keep the codebase same and just change the parts of the code where there are issues wrt. to the new library.

Question is, how to go about setting up a second repository that is linked to the master branch of the first repo ?. I want to do development only in the main repo and then sync the changes to the second repo and change only the code that is relevant wrt. libraries.

Is this the right way to go about this problem? or is there another way.

Thanks!

Adam Miklosi
  • 135
  • 1
  • 2
  • 7
J.Doe
  • 31
  • 1
  • 4
  • 1
    Possible duplicate of [Is it a good practice to use branches to maintain different editions of the same software?](https://softwareengineering.stackexchange.com/questions/134754/is-it-a-good-practice-to-use-branches-to-maintain-different-editions-of-the-same) – Doc Brown Sep 14 '18 at 12:09
  • .. so I would indeed recommend to ignore the already given answers here and try to use the recommendation from the top answer of the link above, which says: *use your preprocessor or build system to differentiate between versions* – Doc Brown Sep 14 '18 at 14:57
  • I can use the build system to differentiate the versions but the code still has to be changed based on the libraries. How do i maintain 3 different versions of the code due to having dependency on different but similar libraries. – J.Doe Sep 14 '18 at 15:05
  • Hard to tell without any information about the programming environment, language and build system, or the specific problem you are facing. Ask a better question, get better answers. – Doc Brown Sep 14 '18 at 15:53
  • 1
    Have a look at this question: [Git Repository Structure for Interdependent Projects](https://softwareengineering.stackexchange.com/q/372927/118878). You might be butting your head against a similar problem. – Greg Burghardt Sep 14 '18 at 17:05
  • 1
    Possible duplicate of [Git Repository Structure for Interdependent Projects](https://softwareengineering.stackexchange.com/questions/372927/git-repository-structure-for-interdependent-projects) – Greg Burghardt Sep 14 '18 at 17:06

3 Answers3

1

If I understand your problem correctly it should be possible to do this with a separate remote bransch.

Create a new branch: git checkout -b feature_branch_name

Edit, add and commit your files.

Push your branch to the remote repository: git push -u origin feature_branch_name

Then set up a build for each branch library combination in your CI environment.

Make a good plan for pushing and merging or addapt Git Flow.

dokvist
  • 29
  • 4
1

The problem you are trying to solve is Dependency Management. This is not something Git, Git Submodules, or any other kind of source control can address. Depending on the tech stack you are working with, you have a bunch available:

  • C#/VBScript: NuGet
  • JavaScript: NPM
  • Ruby: RubyGems
  • Java: Maven
  • Python: pip

There are many others.

Dependency management allows your code to utilize different versions of the same library, which is the root problem you are having. This may translate to using branches in Git to develop this, or configuration options during the build process. Regardless, this isn't going to be solved by Git.

Greg Burghardt
  • 34,276
  • 8
  • 63
  • 114
0

It sounds like what you are looking for is git submodules:

git submodules

Lewis Pringle
  • 2,935
  • 1
  • 9
  • 15
  • but isn't submodule a different repo that has dependency to the first? here I have the code dependent on a library – J.Doe Sep 14 '18 at 15:00
  • this reads more like a comment, see [answer] – gnat Sep 14 '18 at 17:08
  • @J.Doe I believe you have this exactly reversed. submodules ARE what you want. You create a repository "Library". Then create another repository for "MyApp". THEN -inside the MyApp repository, you git submodule add Library. A 'submodule' is a REFERENCE to another repository. – Lewis Pringle Sep 14 '18 at 18:17
  • @gnat Brevity is sometimes appropriate ;-). – Lewis Pringle Sep 14 '18 at 18:20
  • the fact that you had to explain what you mean in a comment that is about twice longer than the answer suggests that this is probably not the case when brevity is appropriate – gnat Sep 14 '18 at 20:49
  • @gnat I would agree except that I was explaining what was said - NOT by me - but in the referenced document about git submodules. The reason for my brevity is that I referenced an article that explained more fully. I couldn't have anticipated which parts of that longer article needed clarification. But still - you maybe right. Maybe I should have said more. I just wasn't sure what more to say. Sorry... – Lewis Pringle Sep 14 '18 at 21:44