What does cherry-picking a commit with Git mean?

81    Asked by mike_4071 in Devops , Asked on Sep 3, 2025

What does it mean to cherry-pick a commit in Git, and when should you use it?  Git cherry-pick lets you apply specific commits from one branch to another, giving you precise control over which changes get merged.

Answered by Mack Ryan

In Git, cherry-picking a commit means selecting a specific commit from one branch and applying it to another branch without merging the entire branch history. It’s like saying, “I want this one particular change, but not everything else from that branch.” This is very useful when you only need certain bug fixes or features without pulling in unrelated work.

Here’s how it works and when to use it:

Basic usage

 To cherry-pick a commit, you first switch to the branch where you want the change and then run:

 git checkout target-branch
git cherry-pick

 The commit identified by will be applied to your current branch.

When to use cherry-pick

  • Applying a bug fix from one branch to another (like moving a hotfix from dev to master).
  • Reusing a specific feature or update without merging all other commits.
  • Quickly copying changes between long-lived branches.

Important points to remember

  • If the commit conflicts with existing code, Git will pause and ask you to resolve conflicts before continuing.
  • Cherry-picking creates a new commit with a new hash, so it’s not the same as the original commit—it’s a copy.
  • Overusing cherry-pick can make your history messy, so it’s best for selective, small changes.

 In short, cherry-pick is like picking a single fruit from the tree instead of taking the whole branch. It gives you precision and flexibility, but you should use it carefully to keep your Git history clean.



Your Answer

Interviews

Parent Categories