Course contentsShow
← Software Engineering
Lesson 69 of 1,9332. Version Control with GitFree lesson

Cherry-Picking Commits

Learn to apply specific commits from one branch to another using git cherry-pick for selective history integration.

Cherry-Picking Commits

You'll learn how to selectively apply individual commits from one branch to another without merging entire branches.

The Core Idea

Sometimes you need just one specific change from another branch—not the whole branch. Maybe a teammate fixed a critical bug on a feature branch, but that feature won't be ready for weeks. You want just that bug fix in your main branch right now.

git cherry-pick lets you do exactly that: copy a single commit (or a few specific commits) from anywhere in your repository's history and apply it to your current branch.

How It Works

Think of your commit history as a garden with different branches of a tree. Cherry-picking is like plucking one specific cherry (commit) from one branch and grafting it onto another branch. The commit's changes get applied, but it becomes a new commit with a new hash on your current branch.

The basic command:

git cherry-pick <commit-hash>

This takes the changes introduced by that commit and creates a new commit on your current branch with those same changes.

When to Use It

  • Applying a hotfix from a development branch to production
  • Backporting a fix to an older release branch
  • Selectively incorporating work without merging unrelated changes
  • Recovering specific changes from an abandoned branch

Potential Conflicts

Just like merging, cherry-picking can cause conflicts if the changes don't apply cleanly to your current branch. You'll resolve them the same way you learned with merge conflicts.

Key Takeaway: git cherry-pick applies specific commits from one branch to another, creating new commits with the same changes—perfect for selective history integration without full merges.