.gitignore for Xcode projects: what to ignore and an example file
Codemia Knowledge Hub ·
An Xcode project's .gitignore should exclude user-specific Xcode state (*.xcuserstate, *.xcuserdatad), DerivedData, build output, package manager artifacts (CocoaPods Pods/, Carthage/Build/, SwiftPM .build/), archives, debug symbols, logs and secrets like .env. Add the file at the project root and commit it.
Example .gitignore for Xcode
Why these files stay out of Git
Xcode generates user-specific settings, derived data, build outputs and logs as you work. Ignoring them:
- Keeps the repository clean, with only files that need version control.
- Reduces repository size, which also speeds up cloning and fetching.
- Reduces merge conflicts, since temporary and per-user files are not shared.
- Protects secrets, so passwords, API keys or private information do not end up in a public repository.
| Element | Purpose |
| Xcode files | Excludes .xcworkspace, .xcuserstate, etc. |
| DerivedData | Excludes project build intermediates and outputs |
| Build Products | Excludes the /build directory |
| Package Manager | Excludes files generated by package managers (e.g., Carthage, CocoaPods, SwiftPM) |
| Temporary Files | Excludes temporary files used during development |
.gitignore pattern syntax
- Comments: Lines beginning with
#are comments. - Blank Lines: Ignored and can be used for better readability.
- Wildcards: Use
*to match any number of characters and?to match single characters. - Directory Ignore: Appending a
/to the end of a pattern will match a directory. - Negation: Patterns can be negated by starting with
!, indicating that files matching the pattern should not be ignored.
In the example above, !default.xcworkspace uses negation to keep one workspace file that *.xcworkspace would otherwise ignore.
Adding the file to your repository
- Create a file named
.gitignorein your Xcode project directory. - Open it in a text editor.
- Add the patterns for the files and directories you want to exclude.
Then commit it:
Untracking files that were already committed
.gitignore only affects untracked files. If you add patterns for files Git already tracks, remove them from the index and recommit:
Related reading
- Given a view, how do I get its viewController?
- Giving UIView rounded corners
- Global constants file in Swift
- GMSGroundOverlay animating - should I be using a CATiledLayer?
- Git ignore local changes to portions of tracked files
- Git Ignores and Maven targets
- GMSPlacesClient cancel request
- Good way of getting the user's location in Android
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseNo course covers this one yet
Basis Lab writes one for you from a sentence about what you want to be able to do, then teaches it and checks you understood. Your first course is free.
Build my courseData Structures & Algorithms practice on Codemia
Step through 300+ coding interview problems with animated visualisers that show the data structure changing as the code runs. The Blind 75 are free.