0

I've read various git tutorials but still have some open questions regarding how git repositories & branches should be used.

Here's the situation i have:

I have a code base "A" which is maintained by external partner and I do receive source code updates every few months for it. Based on the code base "A" I've built another product "B" which is my core product. Then, I use product B as a base for my customers. Each customer has it's own small adjustments. Therefore, I maintain separate code base for each customer as well. Visually it would look something like this:

     A
     |
     B
  / / \ \       
 C  D  F G

Now to the problem:) Every time changes occurs on code base "A" or "B", I have a daunting task to merge all changes to other code bases. I am looking for a way how to leverage Git to ease this code merge task for me.

By reading tutorials, I learned a lot. But, still I have fundamental question of how my repository/branch structure should look like. Here are my questions:

  • Do I need to have repository for each code base?
    • If yes, how I can perform code merges between different repositories?
  • Should I have one repository with multiple branches for each code base?

    • what should be my master branch? A or B?
    • how should the merge performed? by using rebase?
    • are branches stored on the separate folders?
  • Is there another (better) way for solving the problem?

Any help would be great! Thanks

Gintautas
  • 33
  • 3

1 Answers1

0

It's not that clear how clean the cut between A and B is. You can either decide to put it all in one repository and separate the directories, or put them in separate repositories and make A a submodule of B, perhaps. It depends a bit on how you're receiving these updates.

As for the branches; you could have one branch for each variant of B, and then whenever you make an update to B that the other codebases should also have, you simply git merge B into the other branches as appropriate. As you appear to be modifying B (instead of extending it) for each of the codebases, having B as a submodule would not work here.

With respect to separate folders for branches: no, not directly. When you're viewing one branch, the other code is not available in your working directory. You would have to check out a different branch to switch to the other codebase, changing the contents of the working directory. You could set up multiple working trees, though, if you find yourself switching a lot. That's a bit of an experimental feature, though, and there are a few bugs when you're also working with a submodule. You could also consider simply maintaining multiple instances of the same repository, accepting the overhead.. Or just switch between branches when you need to.

Community
  • 1
  • 1
Joost
  • 4,094
  • 3
  • 27
  • 58
  • There's no clean cut between A and B. I could have the same file "foo.txt" in all branches with different content. For e.g.: on **A** foo.txt is '"boo"'; on **B** '"boo with B"'; on **C** - '"boo with B & C"'; on **D** - '"boo with B & D"' – Gintautas Feb 04 '16 at 21:53
  • Right, the submodules idea does not apply then. That sounds like 6 branches, and merges in one direction (i.e. when A updates, merge it into B, then merge B into C / D / E / F) – Joost Feb 04 '16 at 22:18