What is git cherry-pick, how do you use it, and when should you avoid it?
Short answer
git cherry-pick <commit> takes one commit's diff against its parent and applies it to the current branch as a new commit (different hash). Use it when you need a few specific commits, such as bringing a hotfix from main to a release branch, not to keep two branches in sync.
3 points to say:
- Cherry-pick copies a change into a new commit with a new hash; the original stays on its branch.
- Use
-xto record the source;A^..Bto include A; on conflict,--continue,--skip,--abort. - Fix on
main, then pick down to release, so the fix is never forgotten; for regular bulk syncing use merge or rebase.
Keep reading the deep dive
Create a free account to read the full explanation and follow-up questions, mark questions as studied and review them on a schedule.