Git
Version Control
Coding Tips
Commit History
Cherry-Picking Commits

How to cherry-pick multiple commits

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

Introduction

Cherry-picking multiple commits in Git means applying selected commits from one branch onto another without merging the entire branch. It is useful for backports, hotfix propagation, and pulling over a small subset of changes when a full merge would bring unrelated work.

Cherry-Pick Several Explicit Commits

If you already know the commit hashes, list them in the order you want Git to apply them.

bash
git cherry-pick a1b2c3d d4e5f6g h7i8j9k

Git applies them one after another. The order matters because later commits may depend on earlier ones.

Cherry-Pick a Commit Range

When the commits are contiguous in history, you can cherry-pick a range.

bash
git cherry-pick start^..end

Using start^..end includes both start and end. This is a common point of confusion because plain start..end excludes the left boundary commit.

Review Before You Cherry-Pick

Before applying multiple commits, inspect what is actually in the range.

bash
git log --oneline start^..end

That quick check helps catch the common mistake of pulling in one extra commit or missing the first one in the sequence.

Handle Conflicts Carefully

If a cherry-pick conflicts, Git pauses and lets you resolve the conflict before continuing.

bash
git cherry-pick --continue

If you decide the cherry-pick should not proceed:

bash
git cherry-pick --abort

This is especially important when applying several commits, because one bad conflict in the middle can leave the branch in an in-between state until you either continue or abort.

Use -n When You Want One Combined Result

Sometimes you want the changes from several commits but do not want separate cherry-picked commits in the target branch. Use --no-commit.

bash
git cherry-pick --no-commit a1b2c3d d4e5f6g
git commit -m "Apply selected fixes from release branch"

That stages the changes without committing each one immediately.

Be Careful with Merge Commits

Cherry-picking normal commits is straightforward. Cherry-picking merge commits is more complicated because Git needs a mainline parent choice. If you hit that case, stop and make sure you understand the history before continuing.

For ordinary multi-commit cherry-picks, it is usually better to pick the underlying non-merge commits whenever possible.

Keep an Eye on Duplicate History

Cherry-picking copies changes, not commit identity. If the same logical change later arrives through a merge, you may see duplicate-looking history or conflict noise. That is why cherry-pick is best for surgical cases, not as a general branch synchronization strategy.

Prefer Reviewing the Target Branch First

Before cherry-picking, update and inspect the target branch so you understand what is already there. That reduces the chance of replaying fixes that were already applied under different commit hashes.

Cherry-Pick Is About Intentional Selection

If you are bringing over most of a branch, a merge or rebase is usually the more honest operation. Cherry-pick is strongest when the selection is small, deliberate, and easy to explain in code review.

Common Pitfalls

  • Cherry-picking commits in the wrong order.
  • Using start..end when you meant to include the starting commit.
  • Forgetting to inspect the range before applying it.
  • Leaving a conflicted cherry-pick half-finished instead of continuing or aborting.
  • Using cherry-pick repeatedly where a merge or rebase would better express the real intent.

Summary

  • List explicit hashes when the commits are scattered.
  • Use start^..end when you want an inclusive contiguous range.
  • Check the range with git log --oneline before applying it.
  • Resolve conflicts with --continue or cancel with --abort.
  • Use --no-commit when you want one combined commit instead of many separate cherry-picks.

Related reading
Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

All Rights Reserved.