Cherry-pick copies a single commit from one branch to another.
Cherry-picking is useful when you need one specific commit from another branch without merging the whole branch. Common scenarios: applying a hotfix from main to a release branch, or grabbing a single bug fix from a feature branch.
git switch main
git cherry-pick f7g8h9i[main k1l2m3n] Fix login redirect bug
Date: Mon Mar 10 16:00:00 2025 +0330
1 file changed, 2 insertions(+), 1 deletion(-)
🧠 What happened? Git created a new commit on main with the same changes as f7g8h9i, but with a different hash. The original commit on the other branch is untouched.
git cherry-pick a1b2c3d..e4f5a6ba1b2c3d up to and including e4f5a6b.
git cherry-pick a1b2c3d e4f5a6b f7g8h9igit cherry-pick f7g8h9iCONFLICT (content): Merge conflict in app.js
error: could not apply f7g8h9i... Fix login redirect bug
# Fix the conflict in app.js
git add app.js
git cherry-pick --continuegit cherry-pick --abortgit cherry-pick --no-commit f7g8h9i
git statusChanges to be committed:
modified: app.js
🧠 What happened? The changes are staged but not committed. You can modify them further or combine them with other changes before committing.
← Chapter 10: Tagging · Next: Chapter 12 — Interactive Rebase →