Skip to content
LatchkeyLatchkey home

git cherry-pick: Usage, Options & Common CI Errors

git cherry-pick copies the changes from one or more commits onto your current branch as new commits.

Cherry-pick is how you port a fix to another branch. Conflicts pause it, like a rebase.

What it does

git cherry-pick takes the diff introduced by each named commit and applies it on top of the current HEAD, creating a new commit for each.

Common usage

Terminal
git cherry-pick <sha>
git cherry-pick -x <sha>          # add "cherry picked from" note
git cherry-pick A^..B             # a range of commits
git cherry-pick -n <sha>          # apply without committing
git cherry-pick --continue

Options

FlagWhat it does
-xAppend a "cherry picked from commit" line
-n / --no-commitApply changes without committing
-m <parent>Pick a merge commit, choosing the mainline
--continue / --abort / --skipManage an in-progress pick

Common errors in CI

error: could not apply <sha>… / "after resolving the conflicts, mark them with git add … then run git cherry-pick --continue" - the pick conflicts. Resolve and continue, --skip to drop the commit, or --abort to bail. Picking a merge needs -m.

Using this in CI

CI checkouts are shallow and detached by default, which changes the answer this command gives you. Commands that read history, branch names, or tags need the checkout configured for it.

.github/workflows/ci.yml
- uses: actions/checkout@v4
  with:
    fetch-depth: 0   # history, tags, and git describe all need this

- run: |
    git rev-parse --is-shallow-repository   # expect false
    git rev-parse --abbrev-ref HEAD          # prints HEAD when detached

Frequently asked questions

git cherry-pick: Usage, Options & Common CI Errors?
Cherry-pick is how you port a fix to another branch. Conflicts pause it, like a rebase.
What it does?
git cherry-pick takes the diff introduced by each named commit and applies it on top of the current HEAD, creating a new commit for each.
Common errors in CI?
error: could not apply <sha>… / "after resolving the conflicts, mark them with git add … then run git cherry-pick --continue" - the pick conflicts. Resolve and continue, --skip to drop the commit, or --abort to bail. Picking a merge needs -m.

Related guides

References

Run this faster and cheaper on Latchkey managed runners - self-healing included. Start free → 30-day trial · No credit card