226

What should the typical .gitignore include for Xcode 6?

Also for information regarding the xccheckout introduced in Xcode 5 see here

Community
  • 1
  • 1
Epic Byte
  • 33,840
  • 12
  • 45
  • 93
  • 51
    This isn't a "primarily opinion-based" question. There are files that git should always ignore in XCode, program files such as xcuserdata. The choice to exclude these is in no way opinion based. – Dermot Oct 02 '13 at 07:17
  • 4
    I second Dermot on that one! Not ignoring some files causes errors, therefore there is a definitive best practice. Half of the code examples shared in SO answers could be equally considered opinions as there are other ways of doing things, but there are generally accepted best practices and de facto standards. – rage Oct 31 '13 at 09:54
  • 2
    Maybe closed partly because there's an extensive answer here: http://stackoverflow.com/questions/49478/git-ignore-file-for-xcode-projects . In my research, you are incorrect to say that .xccheckout should be ignored - but it's not 100% clear, and I've logged a bug with Apple asking for an official answer. – Adam Dec 02 '13 at 15:13

3 Answers3

277

1)

The easiest answer is that mine looks like this:

# Xcode
.DS_Store
build/
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
*.xcworkspace
!default.xcworkspace
xcuserdata
profile
*.moved-aside
DerivedData
.idea/
# Pods - for those of you who use CocoaPods
Pods

which I believe is the same .gitignore that GitHub sets up with all their repositories by default.

2)

Another answer is that there's a website called "gitignore.io" , which generates the files based on the .gitignore templates from https://github.com/github/gitignore.

Michael Dautermann
  • 88,797
  • 17
  • 166
  • 215
  • 1
    Thanks, I'm going to use the gitignore from github as it appears to be updated for Xcode 5. – Epic Byte Sep 23 '13 at 00:12
  • 10
    do not forget to remove xcworkspace in case you use cocoa pods if integrating post commit hooks with e.g. travis – Ivor Prebeg Oct 26 '13 at 20:07
  • 1
    please update the following gist: https://gist.github.com/adamgit/3786883 with Xcode 5 specific stuff to keep it up to date! – Mick F Nov 21 '13 at 14:52
  • GitHub doesn't check their .gitignore's - the "official" one for Xcode4 has been badly wrong for a loooooooong time. I would very strongly advise you not to rely on their (unchecked) ignore files. – Adam Dec 02 '13 at 15:14
  • Hi @Adam, can you elaborate a bit? – Michael Dautermann Dec 03 '13 at 06:53
  • 3
    I researched all the files - c.f. http://stackoverflow.com/questions/49478/git-ignore-file-for-xcode-projects - the various, unvetted contributors to the github project clearly did not (I repeatedly see things that should be in there but are missing, and (worse) vice-versa). Obviously, I'm not going to bother tracking / commenting on something that's clearly badly maintained to start with :) - I simply gave up, and wrote a working .gitignore instead, and shared it on StackOverflow – Adam Dec 03 '13 at 12:58
  • I used this but `CalFoo.xcodeproj/project.xcworkspace/xcuserdata/wcochran.xcuserdatad/UserInterfaceState.xcuserstate` is still staged for a commit! Why? – wcochran Mar 06 '14 at 16:48
  • @wcochran perhaps if it was already in the "add" list for a commit before you modified your .gitignore, you have to "`git checkout`" the file to remove it from the add list? I'm not 100% certain, though. – Michael Dautermann Mar 06 '14 at 17:36
  • 2
    Cocoapods suggests thinking twice about ignoring `Pods`: http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control? – ericsoco Mar 27 '14 at 07:08
  • 3
    For what it's worth, I spent a while researching different Xcode & Cocoapods .gitignore files and this one seems to work best for me. The Pods folder is rightly ignored, since it is a generated end-state. Also, the Podfile.lock file is included, which provides valuable metadata about the state of a build during various commits. – Matt Vukas Apr 18 '14 at 01:39
  • 4
    `.idea/` is only needed who using `AppCode` – Wanbok Choi May 21 '15 at 05:32
  • Very useful. I chose not to ignore Pods/ folder, but anyway this gitignore did the trick for me – voghDev Jan 19 '16 at 08:32
  • What does `!default` stand for? – Andrej Apr 07 '16 at 08:42
  • [According to the gitignore documentation](https://git-scm.com/docs/gitignore), "! negates the pattern; any matching file excluded by a previous pattern will become included again". In other words, any Xcode project file that starts with the name of "`default`" **WILL** be included instead of excluded. – Michael Dautermann Apr 07 '16 at 08:48
  • How can I exclude build/ folder but NOT to exclude, f.ex: Folder/build folder? I ran into big trap with simply excluding build/ as it also excluded other folders which had build in the path. – Lukasz May 25 '16 at 17:16
  • GitHub never sets up a default .gitignore for me... is there somewhere I can enable that – Joshua Segal Jun 11 '20 at 15:42
59

If you are creating a new project from scratch in Xcode 6 ... there is no need for a long .gitignore file anymore, as I pointed out in my last post: Apple optimized the standard project file and folder structure to meet the requirements for clear and straight forward git commits. Apple also ignores two file patterns by default if you create the git repository with a Xcode project template:

.DS_Store
UserInterfaceState.xcuserstate

They added them to your .git/info/excludes file in your project directory. So no need to re-ignore them in .gitignore :-)

The only thing I always include in a .gitignore file is the

# Exclude personal Xcode user settings
xcuserdata/ 
crosscode
  • 1,022
  • 8
  • 12
  • 2
    Would you mind putting the third line into the top piece, so I don't have to copy twice every time I come to this answer, please? I hope it gets 133 upvotes, too! – Dan Rosenstark Jan 13 '15 at 22:56
  • 3
    @Yar ... as I described above: the only line you need in your .gitignore file is the exclusion of xcuserdata/. The other two lines are already handled by Apple by default. So no need to copy those three lines to your .gitignore file. – crosscode Jan 15 '15 at 07:02
  • 1
    Oh! Wow. That's actually something I can type by hand. Great stuff, thanks for sharing and good luck here on SO. – Dan Rosenstark Jan 16 '15 at 20:25
6

Refer to Github's Xcode.gitignore file to always have an updated listing of which Xcode files to ignore.

whyceewhite
  • 6,317
  • 7
  • 43
  • 51