Swift .gitignore template
The Swift template ignores the package manager's build directory, per developer Xcode state and symbol archives, and ignores Package.resolved, which an application should usually keep.
At a glance
- Category
- Language
- Patterns in this template
- 22 rules
- Directories ignored
- 6 of the 22 rules end in a slash, so they match directories only
- Re-include rules
- 4 lines start with ! to keep something back
- Also needs an OS template
- macOS is worth adding even so, because .DS_Store appears in asset folders nobody edited.
- Typical companions
- Xcode, since this template covers the language tooling rather than the project files.
In detail
.build is where the package manager puts everything it compiles, including every dependency it fetched. Packages is the older checkout directory from the same tool. Both are restored from the manifest, both contain absolute paths to the machine that built them, and both grow large enough that a committed copy dominates the repository.
Package.resolved is the lockfile, and ignoring it is the choice this template makes on your behalf. It records the exact commit of every dependency the resolver settled on. For an application that you ship, that pinning is the whole point, and the file belongs in the repository so that a colleague and your CI build the same thing you did. For a library it matters far less, since anything depending on you resolves independently.
xcuserdata is per developer state: breakpoints, window layout, which schemes you marked shared. It sits inside the project bundle, so it is easy to commit by accident, and once committed it produces a conflict every time two people open the project. The pbxuser, mode1v3, mode2v3 and perspectivev3 rules are older versions of the same idea, each paired with a negation that keeps the default variant.
DerivedData is the shared build cache Xcode keeps, holding indexes, module caches and intermediate products. *.hmap files are header maps generated during the build. None of it is portable and all of it is rebuilt on demand, usually within one clean build.
The distribution rules cover *.ipa, the packaged application archive, and *.dSYM plus *.dSYM.zip, the debug symbol bundles that let you symbolicate a crash report. Symbol bundles are release artefacts that belong with the build that produced them, in a crash reporting service or an artefact store rather than in git.
Examples
.build/
Packages/
Package.resolved
xcuserdata/
*.xcscmblueprint
*.xccheckout
DerivedData/
*.moved-aside
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
*.hmap
*.ipa
*.dSYM.zip
*.dSYM
Carthage/Build/
.swiftpm/22 lines exactly as the tool writes them, before any common additions you tick.
Things that catch people out
- Package.resolved is ignored by default. If this is an application rather than a library, remove that line so everyone resolves the same dependency commits.
- The .swiftpm directory holds shared scheme definitions as well as user state, so ignoring it wholesale can drop a scheme the team meant to share.
- Carthage/Build is ignored but Carthage/Checkouts is not, which is intentional: checkouts are source, builds are output. Deleting the distinction leaves you committing compiled frameworks.
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 →Xcode .gitignore template
The Xcode template ignores the project bundle's contents while keeping the project file and shared data, the only way to share schemes but not sessions.
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.
Kotlin .gitignore template
The Kotlin template covers the same class and archive output as Java, plus the .kotlin session directory the newer compiler writes into the project root.
Dart .gitignore template
The Dart template ignores the tool directory, generated docs and compiled JavaScript output, and ignores pubspec.lock, which an application should commit.
Scala .gitignore template
What the Scala template ignores: the target output directory, the build server protocol folder, and the caches that Metals and Bloop keep inside the project.
R .gitignore template
The R template ignores saved workspaces, session history, rendered vignettes and check output, plus the .httr-oauth file that stores live access tokens.
Tools for this
- .gitignore Generator Generate .gitignore files for any project - 50+ templates for languages, frameworks, IDEs, and OS