Skip to main content

Sign in

Save your progress and access it from any device.

Or with email

Don't have an account?

Privacy policy

Git cherry-pick: apply a specific commit

Want to grab a single commit from another branch without merging everything? git cherry-pick lets you copy a specific commit to exactly where you need it.

When to use cherry-pick?

Urgency

Production hotfix

A critical fix is on a dev branch. You need to apply it immediately to main/production without taking the rest of the work in progress.

Selection

Pick a specific commit

A branch contains several commits but you only want one particular change. Cherry-pick lets you choose.

Backport

Port to an older version

A fix made on the latest version also needs to be applied to an older maintenance version.

Cherry-pick in practice

Apply a commit and handle conflicts.

Simple cherry-pick

With conflict

Best practices

Prefer merge or rebase when possible

Cherry-pick creates duplicate commits. If you want to integrate all work from a branch, merge is more appropriate.

Keep track of the original commit

In the cherry-pick message, Git adds a reference to the original commit. Keep this info for traceability.

Test after cherry-picking

A commit that works in its original context may not work in a different context. Always test after cherry-picking.

Part of the Git Branching Workflow guide

A

GitQuest is created by Anaïs (nouvelle fenêtre), web developer and head of education, specializing in tech training and digital accessibility.

Questions about git cherry-pick

Practice cherry-pick in GitQuest

GitQuest investigations include situations where you need to apply specific commits.

Start practicing now