git-cherry-pick – Apply the changes introduced by some existing commits. Cherry picking in git means to choose a commit from one branch and apply it onto another. This is in contrast with other ways such as merge and rebase which normally applies many commits onto a another branch.
In another word, Cherry picking in Git is designed to apply some commit from one branch into another branch. It can be done if you eg. made a mistake and committed a change into wrong branch, but do not want to merge the whole branch. You can just eg. revert the commit and cherry-pick it on another branch.
Make sure you are on the branch you want apply the commit to.
$ git checkout master
Execute the following:
$ git cherry-pick
#In this case, 62ecb3 is the cherry and you want to pick it!
$ git checkout master
$ git cherry-pick 62ecb3
Cherry picking a range of commits
In some cases picking one single commit is not enough. You need, letโs say three consecutive commits. cherry-pick is not the right tool for this. rebase is. From the previous example, youโd want commit 76cada and 62ecb3 in master. The flow is to first create a new branch from feature at the last commit you want, in this case 62ecb3.
$ git checkout -b newbranch 62ecb3
Next up, you rebase the newbranch commit --onto master. The 76cada^ indicates that you want to start from that specific commit.
$ git rebase --onto master 76cada^
# The result is that commits 76cada through 62ecb3 are applied to master.Code language: PHP (php)I’m Rajesh Kumar, a DevOps, SRE, DevSecOps, Cloud, and Platform Engineering expert passionate about sharing practical knowledge, real-world experiences, and industry best practices. I have worked at Cotocus and regularly write about technology, travel, investing, health, product reviews, and digital marketing through my various platforms.
I publish technical articles at DevOps School, travel stories at Holiday Landmark, stock market insights at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at TrueReviewNow, and SEO and digital marketing strategies at Wizbrand.
Find Trusted Cardiac Hospitals
Compare heart hospitals by city and services โ all in one place.
Explore Hospitals
Good exercise on using
git cherry-pickto apply specific commits. One real-world point worth adding is that cherry-pick often creates hidden complexity in long-lived branchesโespecially when the same fix gets cherry-picked across multiple release branches, leading to duplicate commits and harder merges later. In practice, teams usually prefer backport branches or merge-based workflows unless thereโs a strong release isolation need, and they rely on clear commit tagging to avoid tracking confusion during future integrations.