117

When I try to do this, I get the following error:

gitignore error

Obviously, Windows Explorer doesn't allow me to create this type of file patterns. How can I overcome this problem?

leventunver
  • 2,659
  • 5
  • 18
  • 34
  • 1
    Possible duplicate of [How to create .gitignore file](http://stackoverflow.com/questions/10744305/how-to-create-gitignore-file) – FearlessHyena May 11 '16 at 19:30
  • Possible duplicate of [How to manually create a file with a . dot prefix in windows for example .htaccess](https://stackoverflow.com/questions/5004633/how-to-manually-create-a-file-with-a-dot-prefix-in-windows-for-example-htacce) – Donald Duck Jun 14 '18 at 23:11

5 Answers5

268

I arrive a little late but will give you the trick!!

In the File Explorer, call your file .gitignore. and it will remove the ending '.'

A strange behavior from the file explorer but, hey!, it works

Or create it from a text editor...

Philippe
  • 21,230
  • 5
  • 41
  • 62
12

Windows Explorer doesn't allow you to create files that consist essentially of a file extension only. This is because Windows Explorer has the option to hide file extensions, leaving you with a file you cannot see (see Why doesn’t Explorer let you create a file whose name begins with a dot?). This is not a restriction of Windows itself, or the file system in use, though.

To create a file named .gitignore, you will have to use another tool to create it. A common solution is to create a text file (e.g. test.txt), open it in Notepad, and select Save As... to rename the file to .gitignore.

The Windows command interpreter also allows you to create files without imposing the additional restrictions of Windows Explorer. A more direct solution would then be to create the file from the command line. This can be done using the following command:

copy NUL .gitignore


Note: When dealing with files that don't have a name, it's helpful to disable the option "Hide extensions for known file types" in Windows Explorer. Otherwise Windows Explorer might show files with no names, or hide them altogether.
IInspectable
  • 35,521
  • 8
  • 69
  • 148
  • The explanation why is a bit strange, as it makes no difference if you create it with other tool and view it in Windows Explorer. It's just that they were lazy to fix their stuff, and provided a workaround. – d.popov Sep 27 '17 at 07:28
  • @d.popov: What's strange about the explanation? This is a usability issue, and File Explorer does the Right Thing. There's nothing to fix either, because nothing is broken (other than the *NIX convention to place additional semantics on file names starting with a dot character). In fact, there is code in File Explorer, that explicitly disallows creating files a user potentially cannot see. The 'fix' would be to remove code that's there for a reason. This is a strange comment indeed. – IInspectable Sep 27 '17 at 07:58
  • .gitignore or .hgignore are shown and can be selected/opened/renamed even with the option to hide known extensions. So not allowing to enter it is a bit of an annoying. And the thing with the last dot is very intuitive ;) Of course, that's just my opinion. – d.popov Sep 27 '17 at 09:12
  • @d.popov: You have not made a convincing point, why you believe this to be a defect. You merely reiterated, that you would want to have it another way. The appropriate place to ask for design changes are Microsoft's UserVoice channels. If you insist, that this is a bug, Microsoft Connect is the right place. – IInspectable Sep 27 '17 at 12:01
2

in cmd,just type

 echo. 2>.name_you_want

or

. 2>.name_you_want

to create file.

if creating a dir,just type

mkdir .folder_name_you_want
gogog
  • 307
  • 1
  • 6
1

Use command line instead.
I was also having the same error. The problem was . at the start of file or folder name.
So I created it by command line.

Rashid
  • 946
  • 2
  • 9
  • 23
0

yes just you can do with command propmt for folder creation mkdir .folder_name