Windows Explorer doesn’t allow you to create files that start with .
because it interprets that as not having a file name.
On Linux/UNIX you would simply use: touch .gitignore
.
Windows doesn’t have a touch
command.
But if you run an invalid command and pipe that to a file that starts with a dot, the file will be created.
For example,
If you run foo>.gitignore
the .gitignore file will still be created - even though foo
is not a valid command. Feel free to try with any command, such as bar>.gitignore
.
Even though the command outputs an error, the file is still created.
Here are some other ways that work as well:
copy nul .gitignore
copy con .gitignore
hit enter, then hit ctrl+zcat>.gitignore
hit enter, then hit ctrl+cecho > .gitignore
foo>.gitignore
fsutil file createnew .gitignore 0
nul > .gitignore
notepad .gitignore
- In Windows Explorer, name the file
.gitignore.
(with a period at the end of the file name) and Windows will rename it to.gitignore
bash -c "touch .gitignore"
Let me know if you know of any other ways and I’ll add them to the list.
Jon