Merging pbxproj Files

pbxproj files in Xcode projects hold the list of all the source files, resources, their hierarchy as well as build properties. However, they are a PITA to merge/rebase. Slight divergence between branches inevitably lead to merge conflicts. That would be ok, if resolving these conflicts was easy and the syntax was a bit more forgiving. Mistakes at the time of resolving conflicts, more often than not, lead to a damaged project.

There is a better way!

I have been using mergepbx as my merge driver for project files for a year now and it has been amazing! What mergepbx is is a set of heuristics for resolving merge conflicts. It does a great job at it, failing only a few times in the countless merges I have handled with it.

What’s better, you can totally automate its use. In your ~/.gitconfig file, declaring mergepbx as the merge driver for project files.

#driver for merging Xcode project files
[merge "mergepbx"]
name = Xcode project files merger
driver = ~/Env/mergepbx/mergepbx %O %A %B

[mergetool "mergepbx"]
cmd = mergepbx "$BASE" "$LOCAL" "$REMOTE" -o "$MERGED"

Next time when you are merging or rebasing an Xcode project, mergepbx will detect a project file and spring into action. If, for some reason, it cannot resolve, it will delegate the task to you and you can manually take a look.

It’s really worth trying. Between multiple storyboards introduced by Xcode 7, and mergepbx, I can count on two hands the number of times I had to manually merge these dreaded files!

This was originally posted on my own site.