0Pricing
DevOps Bootcamp · Lesson

Cherry-picking Commits

Understand how to selectively apply individual commits from one branch onto another using `git cherry-pick`.

Cherry-picking Commits is a free DevOps Bootcamp lesson on CoddyKit — lesson 3 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the DevOps Bootcamp learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Selectively Moving Commits

What if you only need one specific change from a branch, not the whole branch? git cherry-pick lets you apply a single commit from anywhere in your repository's history directly onto your current branch.

It's like picking a single cherry from a tree! This creates a brand new commit on your current branch that duplicates the changes of the original.

When to Use Cherry-Pick

Imagine you're working on a big feature branch, and you discover a critical bug fix you made there is also needed on your main production branch right now. You don't want to merge the entire feature branch yet.

This is a perfect scenario for cherry-pick. It helps you port isolated changes without bringing over unrelated work.

The Basic Command

The fundamental command is simple: git cherry-pick <commit-hash>.

  • First, make sure you're on the branch where you want to apply the commit.
  • Then, you need the unique identifier (hash) of the commit you wish to pick.
  • Git will then create a new commit with the same changes on your current branch.
git cherry-pick <commit-hash>

Finding Commit Hashes

To cherry-pick, you need the hash! You can find it using git log.

The --oneline option is super helpful for a concise view:

git log --oneline

Cherry-pick Scenario Setup

Let's set up a simple scenario. We'll create a main branch and a feature/login branch. We'll make a commit on feature/login that we want to bring to main.

We want to bring the "HOTFIX" commit to main.

git init my_project
cd my_project
echo "Initial content" > file.txt
git add file.txt
git commit -m "Initial commit"
git branch feature/login
git checkout feature/login
echo "Login feature added" >> login.txt
git add login.txt
git commit -m "Add basic login feature"
echo "Fix: Login button style" >> style.css
git add style.css
git commit -m "HOTFIX: Fix login button styling"

Executing the Cherry-Pick

Now, switch back to the main branch and apply the "HOTFIX" commit. Let's assume the hash for "HOTFIX: Fix login button styling" was abcdefg.

After running this, a new commit will appear on your main branch with the same changes as abcdefg. Use git log --oneline to see it!

git checkout main
git cherry-pick abcdefg

Handling Cherry-Pick Conflicts

Just like merging, cherry-picking can lead to conflicts if the same lines of code have been changed differently in both histories.

  • Git will pause the operation and mark the conflicting files.
  • Manually resolve the conflicts in the files.
  • git add the resolved files.
  • Complete with git cherry-pick --continue.
# After resolving conflicts in editor:
git add .
git cherry-pick --continue

Picking Multiple Commits

You can cherry-pick more than one commit at a time.

To pick a range of commits (from hashA up to, but not including, hashB):

git cherry-pick hashA..hashB

When to Use (and Not Use)

Cherry-picking is powerful but use it thoughtfully.

  • Good for: Hotfixes, porting small, isolated changes between unrelated branches.
  • Less ideal for: Regularly integrating large sets of changes, as it can lead to duplicate commits and make history harder to follow if not careful. Prefer merging or rebasing for full branch integration.

Quick Check: Cherry-Pick Purpose

You have a commit on your feature/new-design branch that fixes a critical styling issue. You need this fix on your main branch immediately, without merging the entire feature branch.

Recap: Targeted Changes

In this lesson, we learned about git cherry-pick, a useful command for applying specific commits to your current branch.

  • It creates a new commit with the same changes on your target branch.
  • It's ideal for hotfixes or porting isolated changes.
  • You need the commit's hash, typically found with git log --oneline.
  • Be prepared to resolve conflicts, just like with merging.

Mastering cherry-pick gives you precise control over your project's history!

Frequently asked questions

Is the “Cherry-picking Commits” lesson free?

Yes — the full text of “Cherry-picking Commits” is free to read here on the web, and the DevOps Bootcamp course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the DevOps Bootcamp course, upgrade to CoddyKit PRO.

What will I learn in “Cherry-picking Commits”?

Understand how to selectively apply individual commits from one branch onto another using `git cherry-pick`. You practise DevOps Bootcamp with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start DevOps Bootcamp?

No prior experience is required. DevOps Bootcamp on CoddyKit is structured for beginners through advanced learners; this is — lesson 3 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Cherry-picking Commits” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this DevOps Bootcamp lesson?

Yes. Every DevOps Bootcamp lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Manual Merge Conflict Resolution
  2. Interactive Rebasing for History
  3. Cherry-picking Commits
  4. Using Git Rerere to Reuse Conflict Resolutions
← Back to DevOps Bootcamp