Git Cherry-Pick: Commands, Conflicts and UI Steps

A bug fix landed on main this morning, and production runs from a release branch. You do not want to merge main into the release, because that drags in every unfinished feature. You want that one commit, and nothing else.

That is exactly what git cherry-pick does: it copies the change from one commit onto your current branch as a new commit. This guide covers the syntax, ranges, -x and -n, conflicts, merge commits (-m), undoing, and the cherry-pick buttons in GitHub, GitLab and Azure DevOps. Every Git command here was run on Git 2.50.1 in a throwaway repository, and the output is pasted as it appeared. The command reference is the official git-cherry-pick documentation.

Animation of a commit C on main being copied to release/1.0 as a new commit C prime with a new hash, while main keeps C

Why you would cherry-pick

  • Hotfix to a release branch: the fix is on main, the release branch needs only that fix.
  • Backporting a bug fix to older supported versions.
  • Commit on the wrong branch: copy it to the right branch, then remove it from the wrong one.
  • Pulling one change out of a feature branch that is not ready to merge.

If you can merge the whole branch, merge it. Cherry-pick duplicates history: the same change exists as two commits with different hashes. Teams that release from main need it less, see Trunk-based development best practices.

What git cherry-pick does

Git stores each commit as a snapshot plus its parent. Cherry-pick takes the difference between the chosen commit and its parent, then applies that difference on top of your current HEAD and creates a new commit. The new commit keeps the original author, date and message, but has a different hash because its parent is different. The source branch is not changed.

Set up a practice repository

To follow along without risking a real project, create this small repository. release/1.0 is created at the first commit, so it is missing the three later commits.

git init -b main demo && cd demo
echo "v1" > app.txt && git add . && git commit -m "Initial release 1.0"
git branch release/1.0
echo "feature a" > a.txt && git add . && git commit -m "Add feature A"
echo "fix login" > login.txt && git add . && git commit -m "Fix login bug"
echo "feature b" > b.txt && git add . && git commit -m "Add feature B"
git log --oneline --graph --all
* e514dbd Add feature B * d50c832 Fix login bug * 0edb638 Add feature A * b3bdb70 Initial release 1.0

Your hashes will differ from these, so use the ones from your own git log.

Command syntax and a first cherry-pick

git cherry-pick [options] <commit>...

Switch to the branch that should receive the change, then name the commit. Here we want only Fix login bug on release/1.0:

git checkout release/1.0
git cherry-pick d50c832
git log --oneline --graph --all
[release/1.0 88b4541] Fix login bug Date: Thu Jan 1 10:00:00 2026 +0000 1 file changed, 1 insertion(+) create mode 100644 login.txt * e514dbd Add feature B * d50c832 Fix login bug * 0edb638 Add feature A | * 88b4541 Fix login bug |/ * b3bdb70 Initial release 1.0

The release branch now has the fix as 88b4541, not d50c832. Feature A and Feature B were not copied. Remember the rule: check out the destination branch first, then run the command.

Useful options: -x and -n

-x: record where the commit came from

With -x Git appends the original hash to the message. This helps when someone later asks whether a fix reached a release. The Git manual advises against it for commits you cherry-pick only between your own private branches, and recommends it for backports to public branches.

git cherry-pick -x d50c832
git log -1 --format=%B
[release/1.0 b56aef4] Fix login bug Date: Thu Jan 1 10:00:00 2026 +0000 1 file changed, 1 insertion(+) create mode 100644 login.txt Fix login bug (cherry picked from commit d50c8320f0712b41386d27eb4bb962bac9037b20)

-n (–no-commit): stage the change without committing

Use -n when you want to edit the change first, or squash several picks into one commit.

git cherry-pick -n d50c832
git status -s
A login.txt

The file is staged and no commit was created. Run git commit when you are happy.

Cherry-pick multiple commits and ranges

List several commits and Git applies them in the order you write them:

git cherry-pick 0edb638 d50c832
git log --oneline
d50c832 Fix login bug 0edb638 Add feature A b3bdb70 Initial release 1.0

For a sequence, use a range. The two-dot form A..B excludes A and includes B. To include the first commit, use A^..B.

git cherry-pick main~2^..main
[release/1.0 0edb638] Add feature A [release/1.0 d50c832] Fix login bug [release/1.0 e514dbd] Add feature B e514dbd Add feature B d50c832 Fix login bug 0edb638 Add feature A b3bdb70 Initial release 1.0

Here the picked commits have the same hashes as the originals. That only happens because the parent commit and the timestamps were identical in this scripted test. In a real repository the copies get new hashes, as in the first example. With main~2..main (one dot pair, no caret) the same run copied only the fix and Feature B. If you cherry-pick a commit that is already on the branch, Git stops with an empty-commit message, covered under common problems. You can also combine -n with several commits to build one commit:

git cherry-pick -n 0edb638 d50c832
git commit -m "Features A and fix in one commit"

Resolve conflicts: –continue, –abort, –skip

A conflict happens when the target branch changed the same lines. To reproduce it, we added a different login.txt on release/1.0 first, then picked the fix:

git cherry-pick main~1
Auto-merging login.txt CONFLICT (add/add): Merge conflict in login.txt error: could not apply d50c832… Fix login bug hint: After resolving the conflicts, mark them with hint: "git add/rm <pathspec>", then run hint: "git cherry-pick –continue". hint: You can instead skip this commit with "git cherry-pick –skip". hint: To abort and get back to the state before "git cherry-pick", hint: run "git cherry-pick –abort".
git status
cat login.txt
You are currently cherry-picking commit d50c832. (fix conflicts and run "git cherry-pick –continue") (use "git cherry-pick –skip" to skip this patch) (use "git cherry-pick –abort" to cancel the cherry-pick operation) Unmerged paths: both added: login.txt <<<<<<< HEAD hotfix on release ======= fix login >>>>>>> d50c832 (Fix login bug)

Edit the file to the result you want (remove the <<<<<<<, ======= and >>>>>>> lines), stage it, and continue:

echo "fix login (merged)" > login.txt
git add login.txt
git cherry-pick --continue
git log --oneline
[release/1.0 fe18735] Fix login bug Date: Thu Jan 1 10:00:00 2026 +0000 1 file changed, 1 insertion(+), 1 deletion(-) fe18735 Fix login bug b939b38 Patch login on release b3bdb70 Initial release 1.0
  • git cherry-pick --continue: finish after you resolved and staged the files.
  • git cherry-pick --abort: cancel and return to the state before the cherry-pick. In our test git status -sb afterwards printed only ## release/1.0, a clean branch.
  • git cherry-pick --skip: drop the current commit and move on to the next one in a multi-commit pick. The log afterwards still ended at Patch login on release.
  • git cherry-pick --quit: forget the operation but keep the working tree as it is. In our test the conflicted file stayed marked AA, so use this only when you want to finish by hand.

Cherry-pick a merge commit with -m

A merge commit has two parents, so Git cannot know which side you want. Without -m it refuses. We merged a small topic branch into main with --no-ff and tried to pick it:

git cherry-pick main
git cherry-pick -m 1 main
error: commit 04303a4e61f94ead64ab1a0db9aac6fdc78f4f1d is a merge but no -m option was given. fatal: cherry-pick failed [release/1.0 d606a6a] Merge topic into main 2 files changed, 2 insertions(+) create mode 100644 t1.txt create mode 100644 t2.txt

-m 1 means parent number 1, the mainline, is the base. Git then applies the changes the merge brought in (the topic branch files t1.txt and t2.txt). Parent 1 is usually the branch that was merged into, so -m 1 is the common choice. The result is a normal single-parent commit, shown in the graph as a lone commit on the release branch, not a merge.

Undo a cherry-pick

The right undo depends on whether you pushed.

  • Not pushed yet: git reset --hard HEAD~1 removes the cherry-picked commit. This discards uncommitted work too, so check git status first.
  • Already pushed or shared: use git revert, which adds a new commit that cancels the change and does not rewrite history.
git revert --no-edit HEAD
git log --oneline
[release/1.0 556906d] Revert "Fix login bug" 1 file changed, 1 deletion(-) delete mode 100644 login.txt 556906d Revert "Fix login bug" 88b4541 Fix login bug b3bdb70 Initial release 1.0

If you reset the wrong thing, git reflog lists where HEAD used to be. To see which commits of main are not yet on a release branch, use git cherry -v release/1.0 main: a + means the change is missing, a - means an equivalent change is already there. In our test it printed - for a commit we had picked and + for the one we had not.

Cherry-pick in GitHub, GitLab and Azure DevOps

Not every hosting service has a button. This section reflects each vendor’s documentation as of today. I did not click through any of these screens myself, so the labels may differ slightly in your tenant or version.

GitHub

  • I could not find a documented cherry-pick button in the GitHub web interface, so check the current interface before relying on it. Microsoft’s Azure Repos documentation states this, and GitHub’s own documentation describes cherry-picking only for GitHub Desktop. I could not find an official GitHub page that describes a web UI cherry-pick, so I would not count on it being available.
  • In GitHub Desktop: click Current Branch, choose the branch that has the commit, open the History tab, select one or more commits, right-click and choose Cherry pick commit, then pick the destination branch. You can also drag the commit onto the branch in the Current Branch menu. Push afterwards.
  • Otherwise use the command line, then open a pull request from the new branch. See the GitHub Desktop cherry-pick guide, and our earlier post Cherry pick in Git for trunk-based development.

GitLab

GitLab has a built-in cherry-pick dialog, documented in Cherry-pick changes. To cherry-pick a single commit:

  • Find your project, then in the left sidebar select Code then Commits.
  • Select the commit title, then in the upper-right corner select Options then Cherry-pick.
  • In the dialog choose the project and target branch. Optionally select Start a new merge request with these changes.
  • Select Cherry-pick.

To copy a whole merged merge request, open it, find the Merged by report and select Cherry-pick in its upper-right corner. This needs the merge-commit method, or a squashed or single-commit request when fast-forward is used. When you cherry-pick a merge commit in the UI, the mainline is always the first parent. For another parent use the command line with -m. If the target branch has conflicting changes, GitLab reports an error and tells you to cherry-pick locally.

Azure DevOps (Azure Repos)

Per Microsoft’s cherry-pick documentation, Azure Repos supports cherry-pick in the browser through pull requests, mainly to apply a hotfix to another branch:

  • On a completed pull request, select Cherry-pick on the Overview page. For an active pull request, select Cherry-pick from the More options menu.
  • Azure DevOps creates a new topic branch from the target branch you choose, copies the pull request changes onto it, and prompts you to create a new pull request into that branch.
  • Visual Studio 2022: Git then Manage Branches, right-click the target branch and choose Checkout, right-click the source branch and choose View History, then right-click the commit and choose Cherry-Pick. Visual Studio cherry-picks one commit at a time.

Not verified: the exact wording of the dialog fields that follow the Cherry-pick button in Azure DevOps, and the Azure DevOps Server menu layout. See also Add images to README.md on GitHub and Azure if you document the workflow in your repo.

Common problems and fixes

  • “is a merge but no -m option was given”: add -m 1, as shown above.
  • “The previous cherry-pick is now empty”: the change is already on your branch. Our run printed this after picking the same commit twice. Run git cherry-pick --skip, or git commit --allow-empty if you really want the record.
  • “bad revision”: the hash is wrong or not fetched. Run git fetch and check with git log --oneline --all. Typing a name that does not exist printed fatal: bad revision 'nosuchcommit'.
  • “your local changes would be overwritten by cherry-pick”: commit or stash first, with git stash.
  • Repeated conflicts later when you merge the branches: usually harmless, because the same change exists twice. Resolve once, or use -x so people can trace the origin.
  • Wrong order: when picking several commits, list them oldest first so dependent changes apply cleanly.
  • git is not recognized: Git is not installed or not on your PATH, see git is not recognized as an internal or external command.

Frequently asked questions

Does git cherry-pick change the original branch?

No. It creates a new commit on the current branch. The original commit stays where it was, and the two have different hashes.

How do I cherry-pick a range of commits?

Use git cherry-pick A..B, which excludes A and includes B, or A^..B to include A as well. Order runs from oldest to newest.

Can I cherry-pick in the GitHub web interface?

I could not find a documented cherry-pick option in the GitHub web interface, and GitHub’s own documentation covers cherry-picking in GitHub Desktop and on the command line. Use Desktop, the command line, or a tool such as GitLab or Azure DevOps that has a button.

Summary

Check out the destination branch, run git cherry-pick <hash>, add -x for backports, use ranges with A..B or A^..B, resolve conflicts then --continue (or --abort), and pass -m 1 for merge commits. Undo with revert once pushed. Tested: every Git command above on Git 2.50.1 in a local repository. Not tested: pushing to a remote, the GitHub Desktop, GitLab and Azure DevOps screens (taken from vendor documentation only), and cherry-pick with submodules or signed commits.

Found this useful?

Bookmark this page and share it with your team. Get new .NET, cloud and database tutorials in your inbox.

Leave a Reply

Your email address will not be published. Required fields are marked *