Xcode .gitignore template
The Xcode template ignores per developer project state and the derived data cache, while explicitly keeping the project file and the shared scheme directory tracked.
At a glance
- Category
- IDE
- Patterns in this template
- 24 rules
- Directories ignored
- 4 of the 24 rules end in a slash, so they match directories only
- Re-include rules
- 6 lines start with ! to keep something back
- Also needs an OS template
- macOS specifically, since asset catalogues collect file manager metadata files.
- Typical companions
- Swift for the package manager rules, plus the macOS template.
In detail
The three rules at the end of this template do the interesting work. *.xcodeproj/* ignores the contents of the project bundle, then two negations bring back project.pbxproj and the xcshareddata directory. The bundle is a directory pretending to be a file, and inside it sit both the project definition everyone needs and the per developer state nobody else wants.
project.pbxproj is the project definition: every file reference, build phase and target setting. It must be tracked. It is also notorious for merge conflicts, because it is a single large file that the editor rewrites in full and that changes whenever anyone adds a file. That is a real cost of the format rather than something an ignore file can fix.
xcshareddata holds shared schemes, which describe how to build, test and run each target. Marking a scheme as shared moves it from your user data into that directory, which is the mechanism for sharing a run configuration with the team. The xcuserdata rule covers the other side: breakpoints, window layout and unshared schemes, all of which are yours alone.
DerivedData is the build cache: module caches, indexes, intermediate products and build logs. It is normally outside the project directory, but a project configured to use a relative path will produce it inside, and it is large and entirely regenerated.
Pods is the dependency manager's installed sources directory. Whether to commit it is a genuine argument: committing gives you reproducible builds without a network fetch and a much larger repository, while ignoring it relies on the lockfile plus the dependency sources still being available. This template takes the ignore side, which is the more common choice now.
Examples
build/
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata/
*.xcscmblueprint
*.xccheckout
*.moved-aside
DerivedData/
*.hmap
*.ipa
*.dSYM.zip
*.dSYM
timeline.xctimeline
playground.xcworkspace
Pods/
*.xcodeproj/*
!*.xcodeproj/project.pbxproj
!*.xcodeproj/xcshareddata/24 lines exactly as the tool writes them, before any common additions you tick.
Things that catch people out
- A negation only works because the rule is *.xcodeproj/* rather than *.xcodeproj/. Change it to the directory form and project.pbxproj stops being tracked, which breaks the project for everyone.
- Ignoring Pods means a clone cannot build until the dependency install command has been run and the upstream sources are still reachable.
- A scheme only lands in xcshareddata if you tick the shared box. An unshared scheme lives in xcuserdata and is ignored, which is why a colleague's run configuration is missing.
Try it: .gitignore Generator
Pick one or more templates, tick the common additions you want, and copy or download the combined .gitignore.
.gitignore Generator
LOCAL · Browser-OnlyGenerate comprehensive .gitignore files by combining templates for languages, frameworks, IDEs, and operating systems
Language
Framework
IDE
OS
Build Tool
Infrastructure
Common Additions
Preview
Select templates or common additions to generate a .gitignore file.
Related .gitignore templates
All .gitignore templates →Swift .gitignore template
What the Swift template ignores: the package build folder, Xcode user state, derived data and symbol archives, plus the Package.resolved decision it makes.
macOS .gitignore template
Where .DS_Store actually comes from, why it appears in folders nobody edited, and what the rest of the macOS template covers on network and removable volumes.
Flutter .gitignore template
The Flutter template adds generated plugin manifests and per platform build artefacts to the Dart rules, including the iOS pod directory and build modes.
Android Studio .gitignore template
The Android Studio template ignores local.properties, which names the SDK path on one machine, along with build output, captures and native build directories.
Windows .gitignore template
What the Windows template covers: the thumbnail caches Explorer writes into image folders, the folder view settings file, and installer package extensions.
Linux .gitignore template
The shortest template in the collection. Five rules covering editor backup files, file manager settings, per volume trash and NFS silly rename files.
Tools for this
- .gitignore Generator Generate .gitignore files for any project - 50+ templates for languages, frameworks, IDEs, and OS