Home > OS >  New Pull Request when a previous one is pending Merge
New Pull Request when a previous one is pending Merge

Time:12-24

I made some changes to several files of the project on a new branch (let's call it branch_a), I commited them, created the Pull Request, and it was recently reviewed and approved. It's still pending Merge on the master branch.

Now, someone asked for another change. It's a small supplemental change in 1 of the files edited in the first Pull Request.

What's the best way of doing this? Should I ask for the first Pull request to be merged and then create a new branch (branch_b), make my change and create a new Pull Request, ask for review and merge again? Or is there a "cleaner" way, when the first Pull Request is somehow merged with the second one and we don't have to make 2 different merges?

CodePudding user response:

If another change requested is a part of the same feature as in ‘branch_a’, then you can simply make change in the same branch, your PR request will show up those changes, but PR approval will be required again.

If another change requested is outside the scope of feature ‘branch_a’ and it is just a file is same between two changes, then you can create a new branch out of master say ‘branch_b’, complete your changes and raise PR for the same. After ‘branch_a’ is merged into master, you can rebase your second branch ‘branch_b’ to include updated master codebase into branch_b, (or vice-versa if branch_b is merged first). This is especially useful if the order of merge is not decided in advance.

Below are the steps, for rebase, here ‘feature_branch’ is the name of your branch for which you want to perform rebase:

git checkout master
git pull origin master
git checkout feature_branch
git rebase master

Here you might get some conflicts(if there are any) multiple times as per number of commits in your feature_branch. You can resolve the conflicts manually and proceed with further process of rebase with below command:

git rebase --continue

At any point if you think that things are not going well and you would like to cancel rebase process, then execute below command:

git rebase --abort

Finally when all conflicts are resolved and you get message as successfully merged, then execute below command to push changes to origin:

git push --force origin feature_branch

for more information on rebase process follow link: https://www.atlassian.com/git/tutorials/rewriting-history/git-rebase

CodePudding user response:

Branch off the first pull request branch, edit, add, commit, push, and ask for a second PR merging to the first branch. When the first branch is merged the second PR will be reconfigured automatically (by GitHub) to be merged into the main branch.

  •  Tags:  
  • git
  • Related