How to transplant a feature (in a topic branch) to another branch?
Say I have 2 parallel long lived branches:
experimental. And I do some work in a topic branch off of
experimental, and I do this for a couple features (
feature3). How would I transplant the work done in
My initial repository:
master | A-B-C \ D-E I L P \ / \ / \ /| F-G-H \ / \ / | | J-K \ / experimental feature1 | M-N-O feature2 | feature3
My desired repository:
master | A-B-C-----------------------------J'-K' \ D-E I L P \ / \ / \ /| F-G-H \ / \ / | | J-K \ / experimental feature1 | M-N-O feature2 | feature3
One way I can think of doing it is
git checkout master; git cherry-pick J K but that’s error prone and the topic branch might have many different commits.
I would expect it to work something like
git checkout master; git <transplant-commits-in-topic-branch-onto-current-branch> feature2, but all of the rebasing commands I’m familiar with transplant all the diffs from the common ancestor (in this case
A), I want to transplant just the diffs between
K, and not mess with commit hashes.
A bit of context: I’m working on a codebase which was forked off of an original, however I’d like to contribute certain features back. And I develop all the new features in topic branches which I then merge back into my master.
One Solution collect form web for “How to transplant a feature (in a topic branch) to another branch?”
If you’re just trying to move
master, and ‘I’ and ‘K’ don’t depend on changes made in
feature1, you can transplant it with:
git rebase --onto master feature1 feature2
That syntax reads, loosely, as “Rebase
master. It’s original upstream was
Then if you merge
master, it’ll be a fast-forward merge.
feature2 depends on changes in
feature1 that won’t be on
master, the whole situation gets much more complicated, and what you want to do depends entirely on your workflow and how you relate to the parent project. Cherry-picking would work… so long as you’re willing to make later merges of your feature branches complicated against the origin’s master. Or you could rebase all of your branches so that
feature2 applies cleanly against
master, or… about a dozen other methods. It really depends on your long term plan for these branches. In general, cut
feature3 and so on) off
master if you can help it. It’ll save you a lot of trouble down the line.