create account

Why I Love Cherry Pick Git Feature by codingdefined

View this thread on: hive.blogpeakd.comecency.com
· @codingdefined · (edited)
$7.09
Why I Love Cherry Pick Git Feature
Cherry-picking is a git feature which comes in handy in almost all the releases at least in my case when we have different branches like development, stage and prod. 

![](https://cdn.pixabay.com/photo/2020/06/28/19/32/cherry-5350482_960_720.jpg)
PC: Pixabay.com

According to [Coding Defined](https://www.codingdefined.com/2016/09/how-to-merge-branches-with-specific.html)

>Cherry picking in git means to choose a commit from one branch and apply it onto another. It is different than merge because _**cherry-pick**_ will only allow one commit at a time whereas merge applies many commits onto another branch. An example can be when moving changes from the development environment to production environment you only want a certain commit to move rather than the whole branch so you will just cherry-pick the commit onto another branch.

But before telling you why I love cherry-pick, I should just warn you that if you don't know how to use it, you might end up messing the whole branch itself. The git cherry-pick command should be used by caution and thus you should use it only if you cannot use merge.  

![](https://3.bp.blogspot.com/-77AlMu1-6Uw/V-9ECOAQNPI/AAAAAAAACWY/mVLFOqxFuZcnCem3v50k3Na42ROLVNyYgCLcB/s640/cherry-picking2.PNG)

Why I love cherry-pick is because it does not disrupt your current working and thus you can push any commit to any branch. For example, last week I was working on a dev branch and it has like 10 commits which will eventually be moved to stage and production in like 1 week. But I got a request that one feature has to be deployed right away, and that feature I had worked on 2-3 days back and it had one commit. Now I cannot merge the whole development to master because then all the untested code will be pushed to the stage. So my option was to cherry-pick that individual commit from development and move it to stage without changing anything on either dev, stage or prod. And later when we test it in the stage we can merge the whole branch to prod. 

I know I have not followed the one feature one branch principle in Git, which eventually will solve this issue. But this is how our organisation works, we commit everything directly on development and thus I did not have any other option than cherry-picking that commit. Also, cherry-pick can take more than one commit, so if my feature would have been distributed across multiple commits, there would be no problem in cherry-picking the commit. 

There is a difference between merge and cherry-picking, the merge will take all the commits from a branch and merge it to the destination branch whereas cherry-pick will only take single commit or a number of commits of your choice.

![](https://4.bp.blogspot.com/-lnKlGhMHR0U/V-9D57dRKKI/AAAAAAAACWU/Otf0qPDS310vT__aOL0M6W2Sum3gf4RGQCLcB/s640/cherry-picking.PNG)

And as I said I have used cherry-pick a lot of times when we have urgent requirement to push a commit from one branch to other because that's I guess the only way to move commit from one branch to other. Using Cherry Pick is also not that hard, and there are tons of articles on the internet which shows you how to do it. But be cautious and careful before doing the cherry-pick, its better to create a backup of your both source and destination branch before doing this, as this might corrupt or mess both the branch if not done properly. I have learned it hard way as when I have it for the first time, it did mess up a few things and thus I had to spend like one day to fix everything.

---
<center>[![image.png](https://files.peakd.com/file/peakd-hive/codingdefined/C0NEINQq-image.png)](https://www.codingdefined.com/)
[
![image.png](https://files.peakd.com/file/peakd-hive/bala41288/46eaz12N-image.png)](https://discord.gg/bGmS2tE)
</center>
👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , and 42 others
properties (23)
authorcodingdefined
permlinkwhy-i-love-cherry-pick-git-feature
categoryhive-174578
json_metadata"{"app":"peakd/2020.07.1","format":"markdown","description":"Why I love cherry-pick because it does not disrupt your current working and thus you can push any commit to any branch.","tags":["india","stem","technology","palnet","neoxian","git","coding","programming","github","posh"],"links":["https://www.codingdefined.com/2016/09/how-to-merge-branches-with-specific.html","https://www.codingdefined.com/","https://discord.gg/bGmS2tE"],"image":["https://cdn.pixabay.com/photo/2020/06/28/19/32/cherry-5350482_960_720.jpg","https://3.bp.blogspot.com/-77AlMu1-6Uw/V-9ECOAQNPI/AAAAAAAACWY/mVLFOqxFuZcnCem3v50k3Na42ROLVNyYgCLcB/s640/cherry-picking2.PNG","https://4.bp.blogspot.com/-lnKlGhMHR0U/V-9D57dRKKI/AAAAAAAACWU/Otf0qPDS310vT__aOL0M6W2Sum3gf4RGQCLcB/s640/cherry-picking.PNG","https://files.peakd.com/file/peakd-hive/codingdefined/C0NEINQq-image.png","https://files.peakd.com/file/peakd-hive/bala41288/46eaz12N-image.png"]}"
created2020-07-13 08:58:15
last_update2020-07-13 09:02:18
depth0
children1
last_payout2020-07-20 08:58:15
cashout_time1969-12-31 23:59:59
total_payout_value3.578 HBD
curator_payout_value3.509 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length3,758
author_reputation529,296,208,861,558
root_title"Why I Love Cherry Pick Git Feature"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id98,494,226
net_rshares20,068,110,964,264
author_curate_reward""
vote details (106)
@codingdefined ·
#posh https://twitter.com/codingdefined/status/1282602075566731267
properties (22)
authorcodingdefined
permlinkre-codingdefined-qdeh9y
categoryhive-174578
json_metadata{"tags":["hive-174578"],"app":"peakd/2020.07.1"}
created2020-07-13 09:05:57
last_update2020-07-13 09:05:57
depth1
children0
last_payout2020-07-20 09:05:57
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length66
author_reputation529,296,208,861,558
root_title"Why I Love Cherry Pick Git Feature"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id98,494,313
net_rshares0