Skip to content

cherry-pick Git Command Guide

The git cherry-pick command applies changes introduced by existing commits to the current branch. It’s commonly used to incorporate bug fixes or features from other branches without performing a merge.

Terminal window
git cherry-pick [--edit] [-n] [--no-commit] [-x] [-s] [-m <parent-number>] [-p] [-S[<keyid>]] [--signoff] [--gpg-sign[=<key-id>]] [--ff] [--allow-empty] [--allow-empty-message] [--keep-redundant-commits] [--no-affordance] <commit-ish>...
Terminal window
git cherry-pick --continue
git cherry-pick --skip
git cherry-pick --abort
git cherry-pick --quit
OptionDescription
—continueContinue the operation in progress using the information in .git/sequencer
—skipSkip the current commit and continue with the rest of the sequence
—abortCancel the operation and return to the pre-sequence state
—quitForget about the current operation in progress and return to the pre-sequence state
-e, —editEdit the commit message prior to committing
-n, —no-commitApply the changes necessary to cherry-pick but do not make any commit
-xWhen recording the commit, append a line that says “(cherry picked from commit …)” to the original commit message
-s, —signoffAdd a Signed-off-by trailer at the end of the commit message
—gpg-sign[=]GPG-sign commits (default is the current user)
—no-gpg-signDon’t GPG-sign commits
-m Use the nth parent of the commit as the mainline
—mainline Use the nth parent of the commit as the mainline
-p, —strategy-option=recursive,oursUse a merge strategy
—strategy=Use a given merge strategy
—rerere-autoupdateAllow the rerere mechanism to update the index
—no-rerere-autoupdateDo not allow the rerere mechanism to update the index
—allow-emptyPreserve potentially empty commits
—allow-empty-messageAllow commits with empty messages
—keep-redundant-commitsCreate redundant, empty commits even without —allow-empty
—no-affordanceVerbose output showing skipped commits
ParameterDescription
Commit to cherry-pick. Can be SHA-1, branch name, tag, etc.
Terminal window
git cherry-pick 4c3f2b1

Applies the changes from commit 4c3f2b1 to the current branch.

Terminal window
git cherry-pick 1a2b3c4 5d6e7f8

Applies changes from the two specified commits.

Terminal window
git cherry-pick --edit 9h0i1j2

Allows editing the commit message before applying.

Cherry-pick without committing (for staging)

Section titled “Cherry-pick without committing (for staging)”
Terminal window
git cherry-pick -n 2k3l4m5

Applies the changes but doesn’t create the commit, allowing you to review or combine with other changes.

Terminal window
git cherry-pick feature-branch~2

Applies the commit two steps back from the tip of feature-branch.

Terminal window
git cherry-pick --continue

After resolving conflicts, continue the cherry-pick operation.

Skip a commit during multi-commit cherry-pick

Section titled “Skip a commit during multi-commit cherry-pick”
Terminal window
git cherry-pick --skip

Skips the current commit if it can’t be applied cleanly.

Terminal window
git cherry-pick --abort

Cancels the entire cherry-pick sequence and returns to the original state.

Terminal window
git cherry-pick -x upstream-fix

Appends cherry picked from commit... to the commit message.

How do I cherry-pick a commit from another branch?

Section titled “How do I cherry-pick a commit from another branch?”

To cherry-pick a commit from another branch, use:

Terminal window
git cherry-pick <commit-hash>

How can I cherry-pick multiple commits at once?

Section titled “How can I cherry-pick multiple commits at once?”

To cherry-pick multiple commits at once, execute:

Terminal window
git cherry-pick <first-commit> <second-commit>

How do I handle merge conflicts during cherry-pick?

Section titled “How do I handle merge conflicts during cherry-pick?”

To handle merge conflicts during cherry-pick, resolve the conflicts in the affected files, then run:

Terminal window
git cherry-pick --continue

How can I edit the commit message when cherry-picking?

Section titled “How can I edit the commit message when cherry-picking?”

To edit the commit message when cherry-picking, use:

Terminal window
git cherry-pick --edit <commit-hash>

How do I skip a commit during multi-commit cherry-pick?

Section titled “How do I skip a commit during multi-commit cherry-pick?”

To skip a commit during multi-commit cherry-pick, use:

Terminal window
git cherry-pick --skip

Applications of the git cherry-pick command

Section titled “Applications of the git cherry-pick command”
  1. Backporting bug fixes from development branches to release branches
  2. Applying selective commits from feature branches to master
  3. Reordering commits or fixing commit history locally
  4. Creating patch releases with specific fixes
  5. Incorporating upstream changes in forked repositories without full merges
  6. Selective integration of commits from long-lived topic branches