2

I am new to Git and I'm trying to figure out what the best workflow is when dealing with multiple branches that use the same files. The workflow at the office is pretty much to create a new branch for each ticket that comes in. My biggest concern is that when these branches merge to stage and production that all of the changes are implemented.

Example

Lets say I create branchA from production. I then modify app.js and put a pull request to the QA branch.

Now I create a new branch from production called branchB. I then modify app.js and put a pull request to the QA branch.

branchB does not have the changes that were made in branchA.

I feel that if I continue this workflow I will always be in a conflicted state.

What's the best way to work on separate branches, that will be modifying a lot of the same files, and make sure that when they are merged into QA that they contain the latest code?

Thanks for the help.

Pat Zlydak
  • 21
  • 3
  • You are absolutely right, that is exactly what will happen. That is the good and at the same time bad part about branches. You will have to merge all the stuff in at some point. The good thing about git is that is does a darn good job when merging changes. – phoet Oct 25 '13 at 22:36

1 Answers1

0

What is the reason for a separate branch for each ticket? - Usually it gives you the option to merge the solution of the one branch, but reject the one from the other branch. You do a pull request for both and the maintainer can decide to merge them, or not.

If this is the case, your branches have to be independent. If the one branch inserts solution A and the other a conflicting solution B, then the maintainer has either to choose only one of them or manually combine both solutions.


If you are pretty much the only one working on these tickets and all solutions are typically accepted, then you can base the second solution on top of the first one. (which is basically, what git rebase is doing.)

The downside is: If you do it this way you can no longer have the second solution without the first.

=> The best solution depends on your concrete situation.


Sometimes you can get around conflicts by structuring your code to clearly separate different functionality. - But as soon as two solution change the same functionality in a different way. Someone has to decide, how to solve that conflict.

michas
  • 25,361
  • 15
  • 76
  • 121