What Does Cherry-Picking a Git Commit Mean?

Find out what is meant by git cherry-picking a commit

Cherry-picking a git commit means to select a specific commit from any branch and applying it to another. For example, to cherry-pick a commit with the hash "3ba53ff050ef253058088eff5" to a branch called "foo", you would do the following:

# 1: switch to the target branch
git switch foo

# 2: cherry-pick commit and apply it to target branch
git cherry-pick 3ba53ff050ef253058088eff5

When you cherry-pick a git commit, the following is true:

  • The commit in the source branch is not removed;
  • A copy of the commit with the same changes and the same commit message is created in the target branch;
  • The history of the target branch is not altered, but rather added to, as a new, distinct commit is created.

Cherry-picking is useful in certain situations, even though it may not always be a best practice (as it can result in duplicate commits).

Hope you found this post useful. It was published (and was last revised ). Please show your love and support by sharing this post.