Git conflicts in binary files

Updated on 23 Sep 2020

Usually you are not likely to run into conflicts with binary files, because they are most likely to be assets such as png files. However there could be issues if you’re using git-secret or in my example I have changed an image file.

  • master -> I added text to the image that said master branch
  • feature1 -> I added text to the image that said feature1 branch

Keep our version (master)

As expected the image file, picture1.png is causing problems for the merge. As explained before, the image is different in the two branches, however we just want to keep the version in the master branch. The process is the following steps…

  • git merge feature1
  • ARGH, git complains about not be able to auto-merge picture1.png
  • git checkout --ours *.png - we’re checking out our images
  • git add --all - add the files to the staging area
  • git commit -m "merging feature1 into master - but keep our png files" - commit the changes.

And then we just need to add the files to the staging area and do a final commit.

git add --all
git commit -m "merging feature1 into master - but keep our png files"

Use the new version (test1)

We can opt to use the incoming files instead. This uses the option --theirs.

git merge test1
**ARGH**, git complains about not be able to auto-merge **picture1.png**
git checkout --theirs *.png
git add --all
git commit -m "merging feature1 into master - with feature1 png files"