Fix Git merge conflict in binary files without manual editing
When Git hits a binary file conflict, you can't edit it like text. Here's how to pick your version cleanly without opening a hex editor.
So you're in the middle of a merge, and Git throws a CONFLICT (content) on a .png, .pdf, or .dll file. You can't open it in a text editor to resolve differences — binary files don't work that way. This happens most often when two team members both modified a compiled output, an image asset, or a proprietary format like a .psd or .xlsx in different branches.
Git doesn't care what kind of file it is. It detects a conflict when both branches changed the same binary blob and there's no common ancestor that matches either one. The default merge driver doesn't try to merge binary files — it just marks them as conflicted and leaves the mess for you to sort out.
Here's the thing: you don't need a hex editor, a special tool, or a PhD in binary diffing. You just need to tell Git which version to keep — yours or theirs. And there are two solid ways to do it.
Option 1: Use git checkout to pick a side (fastest)
This is the quickest fix when you know which version you want. Open a terminal in your repo and run:
# Keep the version from your current branch (the one you're merging into)
git checkout --ours -- path/to/binary.file
# Or keep the version from the branch you're merging in
git checkout --theirs -- path/to/binary.file
After that, stage the file with git add and continue the merge:
git add path/to/binary.file
git merge --continue
Real talk: this works every time as long as you know which side is right. If you're not sure, use git log --oneline on the file to see which branch has the intended changes.
Option 2: Use git mergetool with a binary-aware tool
If you need to visually compare the two versions (say, for image files or PDFs), configure a mergetool that can handle binaries. I use Beyond Compare or Kaleidoscope for this. Here's the setup:
git config --global mergetool.mymerge.cmd 'mymerge "$BASE" "$LOCAL" "$REMOTE" "$MERGED"'
git config --global mergetool.mymerge.trustExitCode true
git mergetool
Replace mymerge with your actual tool command. For Beyond Compare on macOS, I use this:
git config --global mergetool.beyondcompare.cmd '/usr/local/bin/bcomp "$LOCAL" "$REMOTE" "$MERGED" "$BASE"'
git mergetool --tool=beyondcompare
This opens a side-by-side view so you can see the two binary files and pick the winner. Save the result and stage it.
Option 3: Override the merge driver for future binary files
If you deal with binary files a lot, set Git to always keep your version (or theirs) automatically. Create or edit a .gitattributes file in your repo root and add:
*.png merge=ours
*.pdf merge=ours
*.dll merge=ours
Then define the custom merge driver:
git config merge.ours.driver true
This tells Git: when merging a .png file, always keep the current branch's version and skip the conflict entirely. Works like a charm for compiled assets you know you'll never want to merge.
What if it still fails?
Three things to check:
- The file is still marked as conflicted after
checkout? Rungit statusand make sure you staged it withgit add. - The merge driver didn't trigger? Double-check the
.gitattributessyntax — no spaces around the equals sign. And the driver must be configured before the merge starts. - Git says "binary files differ" but no conflict? That's normal for binary files with no conflict — they just don't diff well. Use
git diff --binaryto see the raw differences if needed, but it's rarely useful.
Skip the hex editor. Skip the manual binary merge hell. Pick a side, stage it, move on.
Was this solution helpful?