If you’re like me, you hate manually resolving merge conflicts in Xcode’s
project.pbxproj file every time both you and one of your teammates add a new file to your project. It’s an “easy” merge in a sense – you always want to keep both sides – but somehow git can’t figure it out. Here’s how to make git merge those pesky
*.pbxproj files for you – without you having to manually resolve conflicts ever again*. (*Well, probably never again. No guarantees, but this almost always works.)
1. Create a .gitattributes file
Assuming you don’t already have one, create a file called
.gitattributes in your project’s root directory.
2. Set the merge strategy to union
Add the following line to your
This will tell git to merge using the
union strategy, meaning it’ll keep both sides (theirs and ours) during a merge. This is almost always what you want in the case of a
*.pbxproj merge conflict.
3. Add the .gitattributes file to git and push your changes
Now that your merge strategy is set, make sure to give the rest of your team this wonderful gift. Add the
.gitattributes file to your git repo:
git add .gitattributes
Then commit and push and you’re good to go!
Update: If you’re looking for a more complex solution that should work in more cases, check out mergepbx. Personally, I prefer the simplicity of the .gitattributes approach and haven’t had any issues with it.