Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What happens when branched branch gets merged

Tags:

git

github

I have a question for which I couldn't find an answer in Git Pro book.

Suppose I created branchA off master, did some changes, commited and pushed for pull request. I'm pretty sure that this branch will get merged to origin/master at some point but I want to create branchB off branchA for further development based on submitted change.

Question is what happens with branchB when branchA will get merged?

My take is that if pull request approver merges branchA then my branchB pull request will already contain commits from branchA and diff will effectively show only changes between branchA and branchB

However if it's not yet merged, pull request for branchB will show changes from both branches and it's up to approver to either merge branchA and then branchB or only branchB.

Please correct my reasoning

like image 805
xwhyz Avatar asked Dec 06 '25 08:12

xwhyz


1 Answers

You had this situation:

                       branch-A
                          v
              1---2---3---4
             /
O---O---O---O
            ^
          master

Then you did this:

                       branch-A       branch-B
                          v               v
              1---2---3---4---5---6---7---8
             /
O---O---O---O
            ^
          master

To summarize the current state:

  • A pull request for A to master will show the difference between A and master, which is effectively commits 1-4
  • A pull request for B to master will show the difference between B and master, which is effectively commits 1-8, and thus includes all changes from A, that has not yet been merged into master

If you now decide to complete the pull request for A, you have this scenario:

                       branch-A       branch-B
                          v               v
              1---2---3---4---5---6---7---8
             /             \
O---O---O---O---------------X
                            ^
                          master

Where X is now the merge commit. After this, with no other changes or operations, if you revisit the pull request for B it should now (again, still) show the difference between B and master, but now it only includes commits 5-8.

If instead you had completed pull request for B first, you had ended up with this:

                       branch-A       branch-B
                          v               v
              1---2---3---4---5---6---7---8
             /                             \
O---O---O---O-------------------------------Y
                                            ^
                                          master

If you now revisit the pull request for A, depending on the tool you would either see an empty diff, or the pull request can be marked as completed (I seem to recall Bitbucket for Enterprise uses this approach), as all changes in A have already been merged successfully.

So to summarize:

TL;DR: Your B-branch is not really affected, but the diff between it and master will initially include all changes from A as well, but after completing PR for A, it will only show diff between B and master, and no longer show the changes from A as they have already been merged. Your paragraph about "My take" is thus spot on.

like image 179
Lasse V. Karlsen Avatar answered Dec 09 '25 00:12

Lasse V. Karlsen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!