BT101
BT101

Reputation: 3826

New pull request when one is already opened

I've created pull request to project from my fork branch. Repo owner will accept it after code review but it can wait a while because he is currently busy. I didn't want to wait and on brand new branch in my fork I implemented next features.

If now I create new pull request will it merge with previous and create one huge pull request? Or there will be two separate PR? I'm worried it will merge because in commits field on GH I see commits from previous PR.

Upvotes: 2

Views: 4938

Answers (3)

caramba
caramba

Reputation: 22480

Figure out the following

                  ___ you created a new branch, call it "branch-01" 
                 /       
master branch __/_______________________

now it depends how you did move on from there and how you did want to move on from there cause there are 2 different scenarios.

Scenario 1: You created a PR branch-01 which contains a few commits containing all the work which needs to be merged back to master. But needs a review so it's like on hold.

Scenario 2: You created a PR branch-01 which contains a few commits containing some work. Now you need those changes to continue the next work. So what you do now is if you are on branch-01 you do git checkout -b branch-01-next-steps now the branch branch-01-next-steps will have the previous work from branch-01 because you created a new branch from there. So this branch is on top of branch-01, looking like so

                                    ______branch-01-next-steps______
                                   /
                  ____branch-01___/ 
                 /       
master branch __/_______________________

Maybe that's what you want and need. But maybe you need a "fresh" new branch from master. What you have to do then is first git checkout master now you are on your local master branch. From there you can do git checkout -b next-steps which will then look like

                  __branch-01..(waiting)              ___next-steps
                 /                                   / 
master branch __/___________________________________/________

if you need to get changes from master which have been merged on remote before you start working on next-steps you have first to go to master git checkout master then type git pull origin master and then git checkout -b next-steps now next-steps will contain the newest changes from remote master.

You can always go back to branch-01 with git checkout branch-01

Upvotes: 5

Programmer
Programmer

Reputation: 36

It'll just be two separate pull requests. They'll both then need to be reviewed and merged into the main branch.

Although if you're including the changes from the 1st branch on your second branch then the 1st branch can be reviewed with those changes, but if merging both you could end up with problems such as conflicts (if you were also making changes to the code that was in that first branch on your second branch for example).

I have had similar experience in the past and what I would do is cancel/decline the 1st pull request (your repo owner may need to do this) instead of merging it, and instead just merge the changes from your latest pull request that contains the changes from both. In my view that's the simplest thing to do.

Upvotes: 1

eftshift0
eftshift0

Reputation: 30156

You can develop features one on top of the other, no problem. The only thing is that it takes a little more work when you want to do operations. So...once your first feature is merged into master (and assuming you didn't have to move it from the point where it is right now), you can rebase feature2 very easily:

git checkout feature2
git rebase master

This works because the revisions that feature2 was started from, they have already been merged into master.

It could get a little bit trickier if you are asked to rebase feature1... then you would need to do something like:

git branch temp feature1 # save current position of feature1, will need it later
git checkout feature1
git rebase feature1
# now... in order to rebase feature2, you have to make sure _not_ to rebase the revisions you have already rebased of feature1
git rebase --onto feature1 temp feature2 # rebase feature2 onto feature1, do _not_ rebase the revisions of the old feature1
git branch -D temp # delete temp branch

Hope that helps

Upvotes: 2

Related Questions