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:
Windows doesn’t have a
But if you run an invalid command and pipe that to a file that starts with a dot, the file will be created.
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
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 .gitignorehit enter, then hit ctrl+z
cat>.gitignorehit enter, then hit ctrl+c
echo > .gitignore
fsutil file createnew .gitignore 0
nul > .gitignore
- In Windows Explorer, name the file
.gitignore.(with a period at the end of the file name) and Windows will rename it to
bash -c "touch .gitignore"
Let me know if you know of any other ways and I’ll add them to the list.