4

Let's say I have branch-1 (branched off master (major update)) and branch-2 (also branched off master (minor update)).

What is the best approach to do when I need to create another branch, e.g. branch-3 and I need to continue the work from both branches while their PRs are still pending?

And what do I do once both the PRs have been approved?

  • 2
    Why would you continue before the branches are merged; what if the PRs don't get approved? What if changes are suggested that invalidate your approach on part 3? You're just piling up more at-risk work. – jonrsharpe May 23 at 6:32
  • @jonrsharpe The person who will do the approval can be on leave or too busy with other priorities (one scenario). But I need to continue work regardless. So am asking what is the safest way given this situation. – catandmouse May 23 at 7:36
  • So fix that problem. There is no point doing work just for the sake of it, to appear to be busy; try to reduce waste and improve your process. – jonrsharpe May 23 at 7:40
6

Caveat: There is not really a good answer to your immediate question. The real issue is that you have an organisational/team bottleneck that is causing risk and potential rework.

Use team knowledge: Is there a local strategy for dealing with this in your organisation? Which of the other branches was created second and how did the author deal with this problem?

  • I would start by reviewing the outstanding PRs to understand the changes.
  • Are you able to assess which if the open PRs might conflict with your planned change?
    • Consider if it's worth the risk of starting from, say, the major update branch.
  • If you must start work, make sure your commits and commit messages are structured to make cherry-picking as painless as possible because this may be what you end up doing.
  • Put clear instruction on your PR for the approver/reviewer regarding the ordering of the PRs.

Finally, but most importantly: Speak to your team - other people PRing to the repo and approvers to let them know this is an issue. If you have a good project manager, they maybe amenable to freeing up resource to mitigate the delay/rework.

2
+25

You should work from a throw-away branch. Just merge the two branches. Continue making some commits on this throw-away branch. When both PRs are in master you just cherry-pick your commits on a fresh branch from master.

0

Create your new branch using:

git checkout -b branch-3 branch-1
git merge branch-2

This creates a branch that has changes from both your pending branches. Two things are most likely to happen after that point.

  1. You will want to pick up changes from master, including merging of your PRs. Just do a git merge master from branch-3 to pick up those changes.

  2. You will be asked to make changes to one or both of your pending PRs. In that case, make the changes on the PR's branch, then git merge branch-1 from branch-3 to pick up those changes.

There are other much less-likely scenarios (assuming you were asked to make the changes by the people who control the repo), like one PR being rejected outright while the other one is accepted into master. In those cases, you'd probably want to do something like git rebase --onto master branch-2, and deal with the big mess.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.