Bitrise Banner

Editorial: I personally use Bitrise

Create a gitignore file for Swift and Xcode development

As I have previously mentioned, everyone should be using source control. One problem that does come with using source control is avoiding adding files that you should not be tracking. These files can include items like binaries, hidden system files, and personal IDE settings.

If you are using git, this is easily solved by setting up what is called a git ignore file. This file contains a specially formatted list of files and folders to be ignored by the source control application. You can use this file to control what is monitored or allowed to be added, this can be done both at a machine and project level.

A perfect example of a file type to be ignored and not added to source control is binary files. These should not be needed as anyone should be able to download the source and build the application. Not to mention that they can grow rather large and are hard to track changes in as the whole file is considered to be changed every time it is built.

You can create a .gitnignore file by hand, or use tools to make it easier and faster. One tool I like to use is

Using to generate a Swift and Xcode file

Using the web application makes the process of creating the pattern matches simple, and it actually works for any language or tool. All you need to do is enter in the box the languages and tools you plan to use and click Create. So for most of us, it will be Swift and Xcode.

GitInore io with swift xcode 1024x424

The newly generated file appears in the browser ready to save. Simply save the file with the name .gitignore in your project folder and the work is done. Remember that it will be a hidden file in the finder unless you are set to show them. Here is the code that generated so you can easily copy and paste if you prefer not to create one.

# Created by,xcode

### Swift ###
# Xcode
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore

## Build generated

## Various settings

## Other

## Obj-C/Swift specific

## Playgrounds

# Swift Package Manager
# Add this line if you want to avoid checking in source code from Swift Package Manager dependencies.
# Packages/
# Package.pins

# CocoaPods - Refactored to standalone file

# Carthage - Refactored to standalone file

# 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:


### Xcode ###
# Xcode
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore

## Build generated

## Various settings

## Other

### Xcode Patch ###

# End of,xcode

Now when you next go to use source control, Git will read the file and follow the instructions. This is a great way to keep junk from building up in your repositories, something your team and community members will greatly appreciate. p.s. it is also a great way to not accidentally upload credentials, I have actually seen DB usernames and passwords in repository code.