2

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.

3 Answers 3

5

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

2
  • My scenerio is second one (middle snippet). I wonder if for example owner will review branch-01 and commit some changes to it then merge it to master and meanwhile I will be working on branch-01-next-steps will I be able to get this changes with just git fetch?
    – BT101
    Jul 3, 2019 at 18:44
  • @dopeCode not that easy but almost. So from you comment (there are multiple ways again) one option. git co master followed by git pull origin master then git co branch-01-next-steps followed by git merge master or leave branch-01-next-steps as is => (option 2) git co master, git pull origin master now you have the changes. then create a new branch git co -b my-fancy-new-branch then cherry pick the commits you need from branch-01-next-steps (I prefer option 2 cause then I can go back to branch-01-next-steps which did not change) but that's just my personal opinion
    – caramba
    Jul 3, 2019 at 18:59
2

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

6
  • So my PR will not merge into one?
    – BT101
    Jul 3, 2019 at 18:19
  • It could if you wanted to... I'm doing this so you can keep features "separate" for management purposes (separate features should be able to move around separately).
    – eftshift0
    Jul 3, 2019 at 18:20
  • Just to be clear, on github and bitbucket, PRs are associated to branches... the PR will hold whatever you include in the branch.... if you decide to put 10 features one on top of the other, they have no way to tell one from the other. It's all related to the content and the revisions of the branch.
    – eftshift0
    Jul 3, 2019 at 18:22
  • My second pull request have also changes from first PR because I need them to develop next features
    – BT101
    Jul 3, 2019 at 18:25
  • 1
    When the first PR is merged, they should go away from the history of the second PR. Actually, they don't go away... they just report less revisions (and changes) because a number of revisions would already be merged into the target branch.
    – eftshift0
    Jul 3, 2019 at 18:26
1

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.

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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