Git 2 reference · Branching and Merging

git cherry-pick Command (Git)

Apply the changes of specific commits from another branch onto the current branch as new commits.

Git 2

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

git cherry-pick [-x] COMMIT...

Parameters

ParameterDescription
-x Add '(cherry picked from commit ...)' to the message.
--continue / --abort After conflicts.

Examples

Backport one fix
git init -q -b main app && cd app
echo '# Shop' > README.md
git add README.md && git commit -q -m 'Initial commit'
git switch -q -c develop
echo fix > fix.txt; git add .; git commit -q -m 'Fix checkout bug'
echo wip > wip.txt; git add .; git commit -q -m 'WIP feature'
git switch -q main
git cherry-pick -x develop~1 > /dev/null
git log --format='%s%n%b' -1

Output

Fix checkout bug
(cherry picked from commit 7cad6a3de1e2da23af3db909283783a9cd7e984f)

Run this on your computer — see “Get Started” for setup.

Several commits
git init -q -b main app && cd app
echo '# Shop' > README.md
git add README.md && git commit -q -m 'Initial commit'
git switch -q -c b; echo 1 > one.txt; git add .; git commit -q -m one; echo 2 > two.txt; git add .; git commit -q -m two
git switch -q main; git cherry-pick b~1 b > /dev/null
git log --oneline

Output

dcec621 two
ddcd6fc one
7f7f133 Initial commit

Run this on your computer — see “Get Started” for setup.

Was this page helpful?