Xcode
Git
ignore file
version control
development tools

.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

plaintext
1# Xcode
2*.xcworkspace
3!default.xcworkspace
4
5# Swift Package Manager
6.swiftpm/
7.build/
8
9# CocoaPods
10Pods/
11
12# Carthage
13Carthage/Build/
14
15# Xcode specific
16*.xcuserstate
17*.xcuserdatad
18*.pbxuser
19*.xcscmblueprint
20
21# Derived data
22DerivedData/
23
24# Archives
25*.xcarchive
26
27# Symbols
28*.dSYM.zip
29*.dSYM
30
31# Temporary files
32*.tmp
33*.swp
34*.lock
35
36# Build Products
37build/
38
39# Log files
40*.log
41
42# Environment variables
43.env

Why these files stay out of Git

Xcode generates user-specific settings, derived data, build outputs and logs as you work. Ignoring them:

  1. Keeps the repository clean, with only files that need version control.
  2. Reduces repository size, which also speeds up cloning and fetching.
  3. Reduces merge conflicts, since temporary and per-user files are not shared.
  4. Protects secrets, so passwords, API keys or private information do not end up in a public repository.
ElementPurpose
Xcode filesExcludes .xcworkspace, .xcuserstate, etc.
DerivedDataExcludes project build intermediates and outputs
Build ProductsExcludes the /build directory
Package ManagerExcludes files generated by package managers (e.g., Carthage, CocoaPods, SwiftPM)
Temporary FilesExcludes 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

  1. Create a file named .gitignore in your Xcode project directory.
  2. Open it in a text editor.
  3. Add the patterns for the files and directories you want to exclude.

Then commit it:

bash
git add .gitignore
git commit -m "Added .gitignore file"

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:

bash
git rm -r --cached .
git add .
git commit -m "Updated .gitignore and cleaned up the repository"

Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Basis Lab
No 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 course
Data 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.

Practice algorithms