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
To get around this I used the following steps
- Create the text file gitignore.txt
- Open it in a text editor and add your rules, then save and close
- Hold SHIFT, right click the folder you're in, then select Open command window here
- 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 extension: .gitignore. will be automatically changed to .gitignore
As simple as things can (sometimes) be: Just add the following into your preferred command line interface (GNU Bash, Git Bash, etc.)
touch .gitignore
As @Wardy pointed out in the comments, touch
works on Windows as well as long as you provide the full path. This might also explain why it does not work for some users on Windows: The touch
command seems to not be in the $PATH
on some Windows versions per default.
C:\> "c:\program files (x86)\git\bin\touch.exe" .gitignore
Note: The path might differ, depending on your setup and installation path.
The easiest way to create the .gitignore file in Windows Explorer is to create a new file named .gitignore.
.
This will skip the validation of having a file extension, since is actually has an empty file extension.