How to copy commits from one branch to another?
There are basically two options here.
- You can use cherry-pick to copy the new commits on
feat2
tocombo
. - Instead of rebasing, you can merge
Cherry Picking
To cherry pick new commits on feat2
to combo
, run the following:
git checkout combo
git cherry-pick <new commit> <new commit> <new commit>
Merging
Or alternately, you can merge instead of rebasing. E.g. To create combo:
git checkout -b combo feat1
git merge feat2
Then, to "merge in new changes" from feat2
, just...
git merge feat2
Likewise, to merge in new commits on feat1
:
git merge feat1
Merging
You can merge instead of rebase. Since your combo branch is just for testing, you don't have to worry about the history being a bit messier.
That is:
git checkout feat2
git branch -b combo
git merge feat1
Later, when you update feat2:
git checkout combo
git merge feat2
Whenever you make an update to feat1 or feat2, merge that into combo.
The disadvantage is that you'll have to merge all commits in both branches. If there are changes you don't want, you'll have to make a separate commit removing those changes in the combo branch.
Rebasing
You can rebase the additional commits from feat2 onto combo.
Suppose you add some commits onto feat2, then to move these commits to combo:
git rebase --onto combo lastcommittoexcludeonfeat2 feat2
Alternatively, before you make the changes to feat2, add a branch or tag, eg:
git checkout -b lastfeat2rebase
git checkout feat2
git commit ... # more commits here to feat2
git rebase --onto combo lastfeat2rebase feat2
Please note, that once you go with the rebase option, you cannot use the merge option anymore. If you use the merge option, you can later decide to go with the rebase option.