I develop many project which are very similar - using the same base features. My scenario assume, that I have the basic branch e.g. 'master', then I create from 'master' new branches e.g. 'project1-dev', 'project2-dev' - Created branches are developed seperately, but sometimes I would like to add new feature for project1-dev, then moving this feature to 'master', and then merge with 'project2-dev'. In Visual Studio 2015 I can use 'Rebase', but it also moving changes added before add new feature.
Is there any way to moving selected commit from 'project1-dev' to 'master', and then merge with 'project2-dev' ?
You can easily merge your new feature from
project1-dev
to bothmaster
andproject2-dev
by keeping that work in a new branch created from the best common ancestors of all three branches. This is wheregit-merge-base
will come in handy.Using this command (notice the usage of the back-ticks):
you will end up with a new branch named
new_feature_branch
, whoseHEAD
is set to the common ancestor ofmaster
,project1-dev
andproject2-dev
.(If you run just
$ git merge-base master project1-dev project2-dev
, you will get the commit SHA of the common ancestor of those three branches.)This new branch is where you will do your new feature work. When completed, you can merge it back to all the three branches without merging other unwanted works into
master
andproject2-dev
.