github/gitignore · Swift.gitignore
Swift .gitignore テンプレート解説
Swift.gitignore が xcuserdata、アプリのパッケージングファイル、Swift Package Manager の .build、Carthage のビルド、fastlane の成果物を無視する理由と、CocoaPods・Package.resolved の判断基準を説明します。
Swift.gitignore は Xcode で iOS・macOS アプリを作るプロジェクトや、Swift Package Manager でパッケージを開発するプロジェクトを対象とする。Xcode のユーザー固有の状態と配布ファイル、依存関係管理ツール(SwiftPM・Carthage・CocoaPods)のビルド結果、fastlane のレポートを扱う。
テンプレートにはコメントアウトされた選択式のルールが多い。Pods/、Packages/、Package.resolved、*.xcworkspace のように、チームの方針によってコミットするかどうかが分かれる項目は既定では無視せず、判断に委ねている。
ルール別の解説
| パターン | 何を、なぜ無視するか |
|---|---|
xcuserdata/ | ユーザー固有の Xcode 状態スキームの選択、ブレークポイント、ウィンドウ配置など開発者ごとに異なる設定が、.xcodeproj・.xcworkspace 内の xcuserdata に保存される。共有すると互いの設定を上書きし続けることになる。 |
*.hmap | ヘッダーマップXcode がビルド中に作るヘッダー検索用のファイルである。 |
*.ipa*.dSYM.zip*.dSYM | アプリのパッケージング配布用のアプリアーカイブと、クラッシュ解析用のシンボルファイルである。ビルドのたびに新しく作られ、容量が大きい。dSYM はクラッシュレポートサービスにアップロードして保管する。 |
timeline.xctimelineplayground.xcworkspace | PlaygroundSwift Playground が実行時に作るタイムラインと内部ワークスペースである。 |
.build/ | Swift Package Managerswift build が依存関係のチェックアウトとコンパイル結果を入れるフォルダーである。いつでも再作成される。 |
Carthage/Build/ | CarthageCarthage がビルドしたフレームワークである。ソースのチェックアウト(Carthage/Checkouts)はコメントとしてのみ残し、選択できるようにしている。 |
fastlane/report.xmlfastlane/Preview.htmlfastlane/screenshots/**/*.pngfastlane/test_output | fastlanefastlane の実行レポートとスクリーンショットである。テンプレートのコメントのとおり、スクリーンショットは必要なときに再生成することが推奨される。 |
実務での注意点
- CocoaPods の
Pods/は無視しないのがテンプレートの既定である。コミットするとpod installなしでビルドできるが、リポジトリが大きくなる。どちらにしてもPodfile.lockはコミットする。 - アプリなら
Package.resolvedをコミットし、全員が同じ依存関係のバージョンでビルドするようにするのが一般的である。 - macOS で作業するため、macOS テンプレート(または Xcode テンプレート)を一緒に選択して
.DS_Storeを防ぐ。
元のテンプレート
Swift.gitignore
# Xcode## gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore## User settingsxcuserdata/## Obj-C/Swift specific*.hmap## App packaging*.ipa*.dSYM.zip*.dSYM## Playgroundstimeline.xctimelineplayground.xcworkspace# Swift Package Manager## Add this line if you want to avoid checking in source code from Swift Package Manager dependencies.# Packages/# Package.pins# Package.resolved# *.xcodeproj## Xcode automatically generates this directory with a .xcworkspacedata file and xcuserdata# hence it is not needed unless you have added a package configuration file to your project# .swiftpm.build/# CocoaPods## We recommend against adding the Pods directory to your .gitignore. However# you should judge for yourself, the pros and cons are mentioned at:# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control## Pods/## Add this line if you want to avoid checking in source code from the Xcode workspace# *.xcworkspace# Carthage## Add this line if you want to avoid checking in source code from Carthage dependencies.# Carthage/CheckoutsCarthage/Build/# fastlane## It is recommended to not store the screenshots in the git repo.# Instead, use fastlane to re-generate the screenshots whenever they are needed.# For more information about the recommended setup visit:# https://docs.fastlane.tools/best-practices/source-control/#source-controlfastlane/report.xmlfastlane/Preview.htmlfastlane/screenshots/**/*.pngfastlane/test_output
テンプレートの出典: github/gitignore/Swift.gitignore @356fd7b (2026-09-11) · CC0-1.0