Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 775
Luca Avatar asked May 24 '12 19:05

Luca


People also ask

What is the purpose of creating a .gitignore file?

You can create a . gitignore file in your repository's root directory to tell Git which files and directories to ignore when you make a commit. To share the ignore rules with other users who clone the repository, commit the . gitignore file in to your repository.

Where do I put the .gitignore file?

A . gitignore file is a plain text file where each line contains a pattern for files/directories to ignore. Generally, this is placed in the root folder of the repository, and that's what I recommend. However, you can put it in any folder in the repository and you can also have multiple .

Is Gitignore automatically created?

1. Using IDE. Some IDE generates the GitIgnore file automatically when creating a new project. As far as I know, all of IntelliJ IDE (Android Studio, RubyMine, PyCharm, etc) already automatically generate the GitIgnore file.


1 Answers

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, 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 extension: .gitignore. will be automatically changed to .gitignore

like image 84
ajcw Avatar answered Sep 28 '22 01:09

ajcw