r15
r15

Reputation: 496

create a separate branch along with git cherry-pickup

Recently I read about cherry picking from this I got that, cherry picking in git means to choose a commit from one branch and apply it onto another.

Now I have to scenario as say I have four commits as A, B ,C and D. Currently I am on commit A and by using git cherry-pick <hash_of D> I pick-up changes of commit D. But when I check the branch it is showing (no branch).

Now I have do such that I can also use cherry-pick and also give the branch name. How can I do this.

Upvotes: 0

Views: 39

Answers (1)

Wally Altman
Wally Altman

Reputation: 3545

Assuming your tree looks like this:

A---B---C---D       master

If you checked out commit A, then you are currently in detached HEAD state, meaning there is no current branch. You cherry-picked commit D, but you're still in detached HEAD state:

A---B---C---D       master
 \
  D'                (no branch)

Here D' is your cherry-picked copy of D. All you have to do is create a new branch.

git branch my-new-branch

Then you will have:

A---B---C---D       master
 \
  D'                my-new-branch

Upvotes: 2

Related Questions