# git cherry-pick Command in CI

> git cherry-pick applies the changes of specific commits onto the current branch. Reference for -x, --no-commit, and continue/abort in backport automation.

Source: https://latchkey.dev/learn/command-reference/git-cherry-pick-command-reference  
Updated: 2026-06-26

git cherry-pick replays the changes from one or more commits onto the current branch.

Backport automation cherry-picks fixes from a main branch onto release branches. The non-interactive flags let CI either commit the pick or stop cleanly on conflict.

## Common flags

- `<commit>` - apply the named commit (or a range with A..B)
- `-x` - append a "cherry picked from commit ..." line for traceability
- `--no-commit` / `-n` - apply changes to the index without committing
- `--continue` - resume after resolving conflicts
- `--abort` - cancel the cherry-pick and restore the prior state
- `-m <parent>` - pick a merge commit, selecting the mainline parent

## Example

```shell
# Backport a fix to a release branch, recording its origin
git switch release/1.x
if ! git cherry-pick -x "${FIX_SHA}"; then
  git cherry-pick --abort
  echo "Conflict: backport needs manual attention" >&2
  exit 1
fi
```

## In CI

Always handle conflicts in scripted cherry-picks: on failure, run --abort and surface a clear message rather than leaving the branch mid-pick. The -x flag adds traceability so reviewers can find the original commit.

## 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
```

> `git rev-parse --abbrev-ref HEAD` returns the literal string `HEAD` on a detached checkout rather than a branch name. On GitHub Actions read `github.ref_name` instead; the git command cannot know what it was checked out for.

## FAQ

### git cherry-pick Command in CI?

Backport automation cherry-picks fixes from a main branch onto release branches. The non-interactive flags let CI either commit the pick or stop cleanly on conflict.

### In CI?

Always handle conflicts in scripted cherry-picks: on failure, run --abort and surface a clear message rather than leaving the branch mid-pick. The -x flag adds traceability so reviewers can find the original commit.

---

Latchkey runs CI/CD that repairs its own failures. Agent entry points: https://latchkey.dev/agent.txt, https://latchkey.dev/openapi.json, https://latchkey.dev/llms.txt
