Search code examples
gitgit-mergerebasepull-request

How to update a brach on which a Pull request has already been made


I have made Pull Requests for "branchA" and "branchB" which is diverged from my local-develop branch. My PR - branchA got merged to origin-develop. I was requested to make some changes on "branchB" after code review. What should I do to get the changes from origin-develop on branchA before making the requested changes?

What I did was -

git checkout develop git pull origin-develop git checkout branchA git rebase develop

And as you thought I messed it up, but I renamed "branchA" to "branchA-updated" and gonna make a new PR from there.

What should be the ideal workflow in these case ?


Solution

  • When a PR is made, it doesn't mean that you cant push to the branch you want to merge. In this case, you should've merged whatever was on branch develop to your branchB:

    1. git checkout branchB

    Situational step: git pull origin branchB (to update your local branchB with whatever is in remote branchB. Mostly needed when multiple developers are pushing to branchB.)

    1. git pull origin develop to apply remote develop changes into local branchB (this step can be done with rebase as well, it depends mostly on the project's git policy.)

    2. git push origin branchB to push local changes from local branchB to remote branchB (therefore, updating the PR)