0

I want to create a new branch and move several commits from MASTER to BRANCH. I already created BRANCH from MASTER commit A.

I can use cherry-pick, but looks like rebase would be better choice.

I tried a command like this (from BRANCH):

git rebase --onto BRANCH A Z   

but the output is not as expected:

    Note: checking out 'b98885d'.

    You are in 'detached HEAD' state. You can look around, make experimental
    changes and commit them, and you can discard any commits you make in this
    state without impacting any branches by performing another checkout.

    If you want to create a new branch to retain commits you create, you may
    do so (now or later) by using -b with the checkout command again. Example:

    git checkout -b new_branch_name

Please point out where I got wrong - thanks.

enter image description here

1 Answer 1

4

From master at Z, copy to BRANCH:

git branch BRANCH

As you’re still on master, reset back to A:

git reset [--hard] A

BRANCH is now where master was, and master is now at A.

2
  • spot on - thanks. Just in case I insist on using git rebase (just to understand a bit more on it) - could it be done in this case?
    – artm
    Commented Jul 6, 2015 at 6:17
  • @artm: No, rebasing isn’t really useful in this case. It changes the parents of a set of commits, but the base here is the same on each branch – A.
    – Ry-
    Commented Jul 6, 2015 at 8:23

Not the answer you're looking for? Browse other questions tagged or ask your own question.