How to add .gitignore file into Xcode project How to add .gitignore file into Xcode project xcode xcode

How to add .gitignore file into Xcode project


  1. When the open panel is showing, press Command-Shift-. and the hidden files will appear, including .gitignore.
  2. Select the .gitignore file and press the Add button.

This works in any app, not just Xcode. It's an obscure feature of NSOpenPanel.


This solution didn't work for me in XCode 8.0 and El Capitan.

I opened a terminal and typed:

defaults write com.apple.finder AppleShowAllFiles YEScd ../PATH_TO_GIT_ROOT touch .gitignore

Then relaunched Finder and my .gitignore file was visible. Edit per .gitignore documentation


There are only three lines of code that you should write to terminal in order to achieve updated .gitignore file for Xcode 12+.

First step is setting a global configuration for .gitignore file from Gitignore.io

git config --global alias.ignore '!gi() { curl -L -s https://www.gitignore.io/api/$@ ;}; gi'

In the second step go to your project folder then generate the .gitignore file for your project.

git ignore swift,macos >.gitignore 

Lastly, commit the generated file.

git commit -m "Add .gitignore file"

You can open the .gitignore file with Text Editor and uncomment any Folder-File that you don't want to commit into your repo.(For example Pods/)