Github pull request for a branch of a branch

1.4k views Asked by At

My git log looks like this:

-------> develop
\---> A
    \---> B

Branch A is based off of develop, and is being reviewed in a pull request. In the meantime, I need to develop more stuff off of the branch, so I create Branch B. There is also a pull request for Branch B into develop, which includes the commits for both Branch A and Branch B.

The review of branch A finishes, and it is merged into develop, at which point, Github says that I need to merge develop into branch B, but if I do this, then usually it generates a lot of merge conflicts and can be difficult to untangle.

Is there a way to do pull requests for both Branch A and B simultaneously, without Branch B's pull request getting confused when Branch A merges in?

3

There are 3 answers

2
SE is dead On

I see a problem with the workflow here. Why are you merging a branch into something other than the branch it was created off?

Changing the workflow like this can get everything working smoothly:

  1. Create branch A off develop
  2. Make the changes (if there's any) that would be needed for developing the "more stuff" you referred to on a different branch
  3. Create branch B off A
  4. Go to the pull request for merging A into develop and leave a comment stating that you're developing more stuff on a branch created off A and want the reviewers to review as if A already had that stuff
  5. Develop the "more stuff" on B
  6. Create a PR for merging B into A just to make sure everything is reviewed
  7. Merge B into A
  8. Review everything one last time just in case
  9. Merge A into develop
0
hgcrpd On

One solution may be to use the Github feature that allows you to change the base branch of a pull request. So the workflow looks like this:

  1. Create Branch A off of develop
  2. Do stuff on A
  3. Create pull request for A to merge into develop
  4. Create Branch B off of A
  5. Do stuff on B
  6. Create pull request for B to merge into Branch A
  7. Merge Branch A when it is ready to go, and change Branch B's pull request to be based off of develop
  8. Merge Branch B when it's ready to go.

Once you change Branch B's base, then I think Github should show the proper diffs, but haven't tested this yet.

0
Sparr On

Github says that I need to merge develop into branch B, but if I do this, then usually it generates a lot of merge conflicts and can be difficult to untangle.

Instead of a merge, rebasing B on top of develop could be less conflict-prone, if the change in refs isn't otherwise a problem for you.