Play video

What are Git Cherry Pick merge conflicts?

Cherry pick applies the changes introduced by the cherry picked commit onto the current branch. If changes introduced by the picked commit conflict with changes to those files on the current branch, you will see a merge conflict.

Merge conflicts can happen when a commit introduced after the branch split made changes OR if there are unstaged changes in your local workspace that conflict with the cherry picked commit.

How do I know if I have a Cherry Pick merge conflict?

After attempting the cherry pick operation, if you have a merge conflict you’ll see a message like this on your screen:

CONFLICT (content): Merge conflict
error: could not apply d81b1f0

Read on to learn how to fix a this type of conflict. If you instead see this message: Aborting fatal: cherry-pick failed - watch this part of my video to learn how to resolve.

How to resolve a Git Cherry Pick merge conflict

1. Find the files that failed the Cherry Pick

Run git status to get more information about which specific files within the commit failed to merge during cherry-pick.

git status

Note the specific files listed under the “Unmerged paths” header in the resulting message, these are the files you need to manually fix in the next step.

Unmerged paths:
    (Use "git add <file>..." to mark resolution)
        both modified:  config.yaml

In the example above, I need to manually resolve conflicts in config.yaml; however, you may have more than one file to fix.

2. Open each file and manually resolve the merge conflict

Open the file in the text editor of your choice (in this example I’ll use vim):

vim config.yaml

Look for the conflict marker (<<<<<<<) that git added to the file during the failed cherry pick. This marker indicates the specific places in the file you’ll need to manually edit. On top you’ll see what that part of the file looked like on main, and on the bottom, what that part of the file looks like in your cherry-picked commit:

<<<<<<< HEAD
Changes introduced by mainline
======
Changes added by the cherry-picked commit
>>>>>>> d81b1f0

Your goal is to manually replace this entire block, with what that part of the file should look like after the merge (essentially manually performing the merge that Git couldn’t automatically do). If this is confusing, watch my video explanation of this part of the process.

Once you’re done editing the file, save it, then repeat this process for any of the files identified in step 1.

3. Stage each file

Stage each file that you manually edited. This indicates to git you’ve resolved the conflicts in these files:

git add config.yaml

4. Continue the Cherry Pick operation

git cherry-pick continue

Git will then kick you into your default text editor to specify a commit message for the new commit. Add a commit message and save the file (if you’re default editor is vim the command to save & quit is ESQ :wq)

Done!

How to cancel a Git Cherry Pick?

If you run the cherry-pick command and find yourself with more merge conflicts than you bargained for (or just want to abort the cherry pick operation), simply run:

git cherry-pick --abort


To learn more about Git Cherry Pick see my article (and accompanying video).