Git Cherry-Pick
Selectively apply commits from one branch to another without merging the entire branch.
Finding Commits to Cherry-Pick
git log main..feature/association-engine --oneline
git log main..feature/association-engine --oneline -p
git log --all --oneline --grep="fix: mailmap"
Cherry-Pick Ranges
git cherry-pick abc1234
The basic form. Applies the diff introduced by abc1234 as a new commit on your current branch.
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.
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
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.
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.
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
git cherry-pick abc1234
# CONFLICT in file.py
# Fix the conflict manually, then:
git add file.py
git cherry-pick --continue
git cherry-pick --abort
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
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.
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
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.
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.