Mastering Git Cherry-Pick: A Guide by Raees Yaqoob Qazi
Today, I explored an interesting Git feature: cherry-pick. Let me share what I learned and how it can make your development process more efficient.
Imagine you’re working on a feature in the dev branch, and you’ve made several commits. However, only one specific change (commit) is ready to be merged into the main branch. Instead of merging the entire dev branch and introducing incomplete features, you can use cherry-pick to select and apply just the desired commit.

Here’s how cherry-pick works:
- Scenario:
- The main branch (master) has these commits:
commit 1,commit 2,commit 3. - The dev branch has additional commits:
commit 4,commit 5,commit 6. - You only want to add
commit 5from the dev branch to the main branch.
2. Commands to Use:
- Switch to the dev branch:
git checkout dev- View the commit history and copy the commit ID of
commit 5: git log --oneline- Switch to the main branch:
git checkout main- Cherry-pick
commit 5into the main branch: git cherry-pick <commit ID 5>
3. Outcome:
- Only
commit 5from the dev branch is now part of the main branch.
Why Use Cherry-Pick?
This method is incredibly useful when you need to:
- Apply a bug fix or a specific feature to the main branch without merging incomplete or unrelated changes.
- Maintain a clean commit history in your project.
Wrapping Up
I hope this explanation simplifies the concept of cherry-picking for you. It’s like magic (jaddu), allowing you to fine-tune your Git workflow with precision.
Here is the YouTube Link: https://youtube.com/@raeesq.?si=v_QK6Q2XXMf9mKep
If you found this helpful, don’t forget to follow, share, and subscribe to stay updated on more development tips!
Happy coding!
Comments
Post a Comment