Home > Enterprise >  Can a branch open multiple pull requests
Can a branch open multiple pull requests

Time:12-21

I am not too familiar with GitHub, but I have a feature branch that I want to merge its current changes to master multiple times. Ideally, I want to break up the pull requests so that one pr doesn't get too long. So for example I want a pr for the frontend first. After that is merged, I will push changes for the backend and create another pr. I wanted to make sure that the same feature branch can have multiple prs to master (but there will only be one open pr).

Is this allowed in Github?

CodePudding user response:

@aspiringsomeone, it is a good strategy to keep each PR incremental, self-contained and concise. However, it is good to create a new branch for new set of changes (features). In GIT, branches are just markers and don't consume too much space/resources. After your PR is merged, you can delete the branch and create a new branch for next PR.

In your case, first branch could be feature1_frontend (Hopefully, these changes don't depend on backend or somehow disabled until backend changes are ready). After PR_1 is merged, you can create feature1_backend branch and use it for next PR, say PR_2. As and when PR review is complete and it is merged, you can delete corresponding branches and move on.

CodePudding user response:

Do not keep a long-lived feature branch on hand and keep merging it (the same branch). That is a good way to end up with a zillion merge conflicts. You should always delete a PR branch as soon as it is merged.

But don't worry. There's a much better approach: In GitHub you can actually open multiple PRs that stem from one another, and that's probably the way to proceed here. So:

  1. Branch off of your main branch to form feature1 and push it and open a PR asking to merge to the main branch.

  2. Branch off of feature1 to form feature2 and push it and open a PR asking to merge to feature1.

  3. Branch off of feature2 to form feature3 and push it and open a PR asking to merge to feature2.

Here's the cool part. When feature1 is approved and merged to the main branch, GitHub will automatically rebase the feature2 PR so that it is now asking to merge to the main branch, which is just what you want. And so on.

  • Related