Git: partially cherry-pick a commit

git cherry-pick allows you to copy a commit another branch to your current one. A common use case is copying a bug fix from a long-running feature branch to another one, so that it can be merged sooner, for example:

$ git switch -c fix-rpm-counter main
Switched to a new branch 'fix-rpm-counter'

$ # Copy a specific commit from the rebuild-dashboard branch
$ git cherry-pick
[fix-rpm-counter 4e31b0b] Fix RPM counter
 Date: Mon Sep 8 00:21:55 2025 +0100
 2 files changed, 13 insertions(+), 13 deletions(-)

One limitation with a straight-up git cherry-pick, as above, is that it always copies the entire commit. If a commit contains multiple changes, but you only want one of them, you’ll need to undo the undesired cherry-picked changes. This can be tedious and error-prone.

In this post, we’ll look at two methods to partially cherry-pick a commit with less hassle.

git cherry-pick -n with unstaging

This first technique uses an extra option of git cherry-pick, but can still be a bit confusing.

  1. Use git cherry-pick with its -n (--no-commit) option to copy the commit, but pause before committing:

    $ git cherry-pick -n 495dbad
    

😸😸😸 Check out my new book on using GitHub effectively, Boost Your GitHub DX! 😸😸😸


Subscribe via RSS, Twitter, Mastodon, or email:

One summary email a week, no spam, I pinky promise.