125

in a XCode project, I offen got xcodeproject/project.pbxproj file changed, but useless info for me, it for compile.

Should I git ignore this file and xcodeproject/projectxworkspace/username.xcuserdata/UserInterfaceState.xcuserstate file?

qichunren
  • 4,405
  • 7
  • 37
  • 48

7 Answers7

146

Update in the light of Swift Package Manager: If you're building a project as a Swift package - you should definitely ignore this file as it can be generated using file system as source of truth. You can do that by using the following command:

$ cd ~/Projects/MyProjectFolder/
$ swift package generate-xcodeproj

For non-SwiftPM answer - see below.

This file holds the list of all the files in the project, settings of targets and which files belong to which targets. It's probably the meatiest file in project bundle. You should not ignore this file. There are few points for this:

  1. You may not want to work on this project alone or;
  2. You're planning on working on project from different machines;
  3. You'll want to share your code base with others;
Eimantas
  • 48,927
  • 17
  • 132
  • 168
  • The pain I met, folder and files which are ignored in `.gitignore` will still added in `project.pbxproj` file and may be pushed to server. The context is I create a test folder to store passwords locally for test purpose, and that folder would be ignored by git but included in `project.pbxproj` file. – Zhou Haibo Dec 29 '22 at 04:39
8

project.pbxproj is an important file in the Xcode configuration bundle. It is responsible for maintaining references to all of the linked files and their groupings, linked frameworks, and most importantly, the project’s build settings. Because of this, we cannot exclude project.pbxproj from version control.

Here is my general .gitignore for my Xcode Project.

# OS X Finder
.DS_Store

# Xcode per-user config
*.mode1
*.mode1v3
*.mode2v3
*.perspective
*.perspectivev3
*.pbxuser
*.xcworkspace
xcuserdata

# Build products
build/
*.o
*.LinkFileList
*.hmap

# Automatic backup files
*~.nib/
*.swp
*~
*.dat
*.dep
Diya Li
  • 1,048
  • 9
  • 21
7

That is the only file that you want in your repos from the xcodeproj bundle. That file holds all of the info for targets files and build settings.

Grady Player
  • 14,399
  • 2
  • 48
  • 76
  • 1
    This answer may once have been true, but is currently wrong. It is neither true that it holds "all the info" (several things e.g. custom executables are stored in a different file, e.g. workspaces are stored in a different file, etc), nor is it true that it's the "only file" that you want to store. c.f. the question about what to include in .gitignore - http://stackoverflow.com/questions/49478/git-ignore-file-for-xcode-projects – Adam Aug 29 '12 at 23:06
  • 1
    that seems well thought out... follow that in the future. – Grady Player Aug 31 '12 at 19:33
5

Unfortunately, if your Build Settings includes code signing, you have to re-enter your code-signing entity after every "git pull" if another team member has changed it. It seems to me this info should be in the user settings, not the global pbxproj file.

Julius Smith
  • 51
  • 1
  • 1
  • 2
    You can setup code-signing so that each of you on the project has a different code-signing profile that matches the same (shared) setting in the project, e.g. by using a wildcard name and then each of you matching it separately, or by e.g. all being on the same iTunes team and sharing profiles. – Adam Aug 29 '12 at 23:08
5

If you exclude project.pbxproj Jenkins builds will fail. So this is important if you use Jenkins.

yiati
  • 995
  • 1
  • 12
  • 27
1

You can use Xcodegen to generate a pbxproj out of a YAML project specification file then you can ignore pbxproj in git and generate them every time you need.

I have already used Xcodegen on a second project which has a modular architecture (many pbxprojs) and more then 8 developers is working on it.

https://github.com/yonaskolb/XcodeGen

Hope it helps.

Cyril Cermak
  • 191
  • 2
  • 4
0

I found that I also need to preserve the xcworkspace file(s). If didn't, project with a sub-project broke.

Paul Cezanne
  • 8,629
  • 7
  • 59
  • 90