How to create a .gitignore file


I need to add some rules to my .gitignore file. However, I can't find it in my project folder. Isn't it created automatically by Xcode? If not, what command allows me to create one?


If you're using Windows, it will not let you create a file without a filename in Windows Explorer. It will give you the error "You must type a file name" if you try to rename a text file as .gitignore

Enter image description here

To get around this, I used the following steps.

  1. Create the text file gitignore.txt
  2. Open it in a text editor and add your rules, then save and close
  3. Hold Shift, right click the folder you're in, and then select Open command window here
  4. Then rename the file in the command line, with ren gitignore.txt .gitignore

Alternatively, HenningCash suggests in the comments:

You can get around this Windows Explorer error by appending a dot to the filename without an extension: .gitignore.. It will be automatically changed to .gitignore.

How to cherry-pick only changes to certain files?

How to undo local changes to a specific file [duplicate]