Skip to content

Posts tagged ‘xcode’


GIT – xcode project file

I have worked on iPhone application full time since last year, Most of that time I spent working on team with multiple developers. And we have been strugling to keep the .pbxproj file in sync across the team. A bit of googling, we ended up in creating a .gitattributes file with the following content

*.pbxproj -crlf -diff -merge

The truth is that it’s way more harmful to disallow merging of that .pbxproj file than it is helpful. As you say, when you add a file unless other people get that file, they have to also add it to their project – in an application of any size, that sucks and it also takes away a huge benefit of source code control in that you cannot really revert to a complete earlier project state just through git.

The .pbxproj file is simply JSON (similar to XML). From experience, just about the ONLY merge conflict you were ever get is if two people have added files at the same time. The solution in 99% of the merge conflict cases is to keep both sides of the merge, which for git at least simply involves removing any >>>>, <<<<, and ==== lines. In fact this is so common that I have created a simple shell script to fix a .pbxproj file in a merge state from git, I run this from within the project directory (at the Classes level):


projectfile=`find -d . -name 'project.pbxproj'`

cat $projectfile | grep -v "<<<<<<< HEAD" | grep -v "=======" | grep -v "^>>>>>>> " > $tempfile
cp $projectfile $savefile
mv $tempfile $projectfile

Worst case if it fails (you ask XCode to load the project and it fails to load), you simply delete the .pbxproj file, check out the master from git, and re-add your files. But I’ve never had that happen in many months of use with this script, again working full time on iPhone applications with several other developers.