Last Updated: January 3, 2026
When working on a team project, you often find that some features or fixes are ready for production while others are still in progress.
Imagine you need to extract just one specific commit from a feature branch to apply to the main branch without merging everything else. This is where cherry-picking comes into play. It allows you to selectively apply commits from one branch to another, making it a powerful tool in your Git workflow.
This chapter delves into the basics of cherry-picking, covering how it works, why it's useful, and what to keep in mind when using it.
At its core, cherry-picking is the act of selecting specific commits from one branch and applying them to another. This contrasts with traditional merging, where the entire history of changes from one branch is combined with another. With cherry-picking, you have the flexibility to choose only what you need.
When you cherry-pick a commit, Git creates a new commit on your current branch that contains the changes from the commit you selected. This new commit has a different hash because it’s effectively a copy of the original changes, but it will have a new parent commit—the current commit of the branch you’re on.
To visualize this, consider the following commit history:
If you decide to cherry-pick commit C from the feature branch while on the main branch, the history will look like this after the cherry-pick:
Here, C' is the new commit created on the main branch, containing the changes from C.
Cherry-picking is particularly useful in several scenarios:
Let’s illustrate cherry-picking with a practical example. Suppose you have the following scenario where you have a feature branch that contains multiple commits, but only one commit needs to be applied to the main branch.
Check out the main branch:
Identify the commit to cherry-pick:
Use git log or git reflog to find the commit hash of the commit you want. Let's say the commit hash is abc1234.
Cherry-pick the commit:
Now, the changes from that specific commit are applied to your main branch. If the commit contains changes that introduce conflicts, Git will notify you, and you will have to resolve them before completing the cherry-pick.
While cherry-picking is powerful, it’s essential to be aware of some pitfalls:
Always review the changes in the commit you plan to cherry-pick. This helps ensure that the changes are indeed what you need and avoids unexpected issues.
To make the most of cherry-picking, consider the following best practices:
-x option to include a reference to the original commit. This preserves the history and context.Now that you understand the fundamentals of cherry-picking, you’re ready to explore the mechanics of using the git cherry-pick command.
In the next chapter, we will look at its various options and how to effectively leverage them in your workflows. This will empower you to make the most out of cherry-picking and handle any situation that arises.