"You must type a file name" error thrown, when I create a .gitignore file on Windows

WindowsGitGitignore

Windows Problem Overview


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?

Windows Solutions


Solution 1 - Windows

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...

Solution 2 - Windows

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.

Solution 3 - Windows

In cmd, just type

echo. 2>.name_you_want

or

. 2>.name_you_want

to create a file.

If creating a directory, just type

mkdir .folder_name_you_want

Solution 4 - Windows

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.

Solution 5 - Windows

You can do this with command prompt for folder creation:

mkdir .folder_name

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionleventunverView Question on Stackoverflow
Solution 1 - WindowsPhilippeView Answer on Stackoverflow
Solution 2 - WindowsIInspectableView Answer on Stackoverflow
Solution 3 - WindowsgogogView Answer on Stackoverflow
Solution 4 - WindowsRashidView Answer on Stackoverflow
Solution 5 - Windowsuser14130203View Answer on Stackoverflow