Search code examples
gitversion-controlbitbucketgit-mergepull-request

Branch A created from Master and branch B from branch A. How to Merge Branch B to master? and what to do with branch A?


Branched out of master and created branch A to work on some test features.

After all tests were passing in branch A, wanted to move all the code to be thread safe and work with the well known ThreadLocal<> class in Java. To not harm the working tests in branch A, I've opened a new branch B from branch A and worked on it.

Now, the tests from branch B are working good and I would like to merge them to the master.

If I will go by the hierarchy I should merge branch B to branch A and then branch A to the master.

But, I think its there is no use in branch A any more.

p.s. - I'm working on BitBucket.

  1. What will happen if I erase branch A ? Would branch B automatically be under master? Or it will be "lost".

  2. What will happen if I merge branch B to the master ? Should I erase branch A afterwards and thats it?

Would love to hear the proper way to work in this situation, and my mistake by working this way.

Thanks


master -> A -> B


Solution

  • You can create new branch C from the master branch and then cherry-pick your commit from branch B to branch C. After then you can merge branch C in to the master branch. Now if you don't want to keep branch A and B then you can delete them. This is one of safest way.