Git Cherry-Pick

Selectively apply commits from one branch to another without merging the entire branch.

Finding Commits to Cherry-Pick

Identify commits on feature branch that are not on main
git log main..feature/association-engine --oneline
Same but with patch content — verify what you’re pulling in
git log main..feature/association-engine --oneline -p
Find a commit by message across all branches
git log --all --oneline --grep="fix: mailmap"

Cherry-Pick Ranges

Cherry-pick a single commit
git cherry-pick abc1234

The basic form. Applies the diff introduced by abc1234 as a new commit on your current branch.

Cherry-pick a range — exclusive start (A is NOT included)
git cherry-pick A..B

This applies commits after A through B inclusive. If A is the parent of the first commit you want, this works. If you want A included, use A^..B.

Cherry-pick a range — inclusive start (A IS included)
git cherry-pick A^..B

The ^ means "parent of A," so the range starts from A itself. This is almost always what you actually want when cherry-picking a sequence.

Cherry-Pick Options

Cherry-pick without auto-committing — stage changes only
git cherry-pick --no-commit abc1234 def5678

Applies the diffs but does not commit. Useful for batching multiple cherry-picks into a single commit, or for reviewing/modifying before committing.

Cherry-pick and edit the commit message
git cherry-pick --edit abc1234

Opens your editor so you can rewrite the message. Use this when the original message references a branch or ticket that doesn’t apply to your target branch.

Cherry-pick a merge commit — specify which parent
git cherry-pick -m 1 abc1234

Merge commits have multiple parents. -m 1 means "diff against the first parent" (the branch that was merged into). -m 2 diffs against the second parent (the branch being merged). Almost always you want -m 1.

Conflict Resolution

Cherry-pick hits a conflict — resolve and continue
git cherry-pick abc1234
# CONFLICT in file.py
# Fix the conflict manually, then:
git add file.py
git cherry-pick --continue
Abort a cherry-pick in progress — return to pre-cherry-pick state
git cherry-pick --abort
Skip the current conflicting commit and move to next in range
git cherry-pick --skip

Use this during a multi-commit cherry-pick when one commit is no longer relevant (already applied, or superseded).

Cross-Repository Cherry-Pick

Cherry-pick from another repository — add as temporary remote
git remote add upstream https://github.com/upstream-org/repo.git
git fetch upstream
git cherry-pick upstream/main~3..upstream/main
git remote remove upstream

The workflow: add the remote, fetch its history into your local object store, cherry-pick what you need, then clean up the remote. The commits now exist in your repo with new hashes.

Cherry-pick from a local repo on disk — no remote needed
git fetch /home/evanusmodestus/atelier/_projects/personal/other-project main
git cherry-pick FETCH_HEAD~2..FETCH_HEAD

git fetch accepts a path. FETCH_HEAD points to whatever was last fetched. This avoids adding/removing a named remote for one-off picks.

Batch Cherry-Pick Workflow

Cherry-pick multiple commits into one — the --no-commit batch pattern
git cherry-pick --no-commit abc1234 def5678 ghi9012
git diff --staged
git commit -m "feat: backport association engine fixes from feature branch"

Stage all the diffs without committing, review the aggregate, then commit once. Cleaner history than three separate cherry-pick commits on a release branch.

Dry-run — check if a cherry-pick will conflict before applying
git stash
git cherry-pick --no-commit abc1234
git diff --staged --stat
git cherry-pick --abort
git stash pop

There is no --dry-run flag. This is the workaround: stash your work, attempt the pick without committing, inspect the result, abort, restore your stash.

See Also

  • Rewriting — interactive rebase for bulk commit manipulation

  • Branches — branch management context