May 21, 2020 in Git

What is git cherry-pick? What are the scenarios in which git cherry-pick can be used?

1 Answer

0 votes
May 21, 2020

Git cherry-pick is a powerful command to apply the changes introduced by one or more existing commits. It allows you to pick a commit from one branch and apply it to another.

git cherry-pick commitSha is the command used for cherry-picking. commitSha is the commit reference.

This command can be used for undoing changes. For instance, if by mistake you have made a commit to a wrong branch, then you can check out the correct branch and cherry-pick the commit to where it should belong.

It can also be used in team collaboration. There can be scenarios where the same code needs to be shared between two components of the product. In this case, if one developer has already written that code, then the other one can cherry-pick the same.

Cherry-picking is also useful in bug hotfixes where a patch commit can be cherry-picked directly into the master branch to fix the issue as soon as possible.

Related questions

+2 votes
Jul 29, 2019 in Agile
0 votes
Sep 17 in Interstellar Git