1

On git I have two branches, Items and Master both of which are several commits ahead of the local master/maser which is in sync with the remove master/master. I want to cherry-pick my branch master F and add it to the local master/master B ready to be committed to the remote master/master. (I believe I understand cherry-pick.)

Do I have to start a new branch to cherry-pick to and then have to rebase the two branches or is there a better way to make this change?

enter image description here

Frank
  • 207
  • 2
  • 6

1 Answers1

0

If you already have a master branch whose B is an ancestor, you don't have to cherry-pick anything: you can directly push it to origin.

The problem with git cherry-pick is that you are:

In your case, a rebase --onto is preferable:

git checkout master
git rebase --onto B E mster

With:

  • B: your "master/master": Replace B by the name of the branch referencing B (origin/master, maybe?)
  • E: the last commit before the F commits
  • master: the most recent commit of F

The OP adds: In the end I actually used git rebase -i HEAD~14 which gave me the ability to see what I was doing. Thanks

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • However, I do not want to push the intervening commits and I do not know any other method. – Frank Dec 03 '19 at 09:32
  • @Frank Do you mean you need to push only F, not E? – VonC Dec 03 '19 at 11:02
  • Yes, E is actually about 10 commits and the work is not yet complete. F stands alone cleanly and should just work as it does not affect the intervening commits. – Frank Dec 03 '19 at 15:08
  • @Frank OK. A `rebase --onto` is in order then. See my edited answer. – VonC Dec 03 '19 at 17:11