2

I tried to create a .gitignore file in my repository's root directory with the command

$ touch .gitginore

in Git Bash.

Enter image description here

But when I looked at the file from the Windows Explorer. It says it's a text document. Isn't it supposed to be of the type File?

Enter image description here

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Rockstar5645
  • 4,376
  • 8
  • 37
  • 62

4 Answers4

8

touch .gitignore works just fine. Windows detects it as a text file but git should works perfectly.

To be sure of it, you can type ls -la and you should see all your files with their extensions, including .gitignore just like in the following picture:

screenshot

Gino Mempin
  • 25,369
  • 29
  • 96
  • 135
Youkool
  • 96
  • 1
  • 4
    Please do not post terminal contents as screenshots. Paste the text directly into your answer. https://meta.stackoverflow.com/questions/303812/discourage-screenshots-of-code-and-or-errors – Melebius Jan 11 '18 at 13:20
  • .gitignore is a text file, And the explorer of windows detect files by extension to open it, it has no impact on git. – pdem Jan 11 '18 at 13:22
2

Since the question does not specify any required tools, this contains a solution if you want to create a .gitignore file using command prompt or Windows Explorer.

Command Prompt:

In case one receives the following error message on a Windows 10 system in command prompt because touch is a command of git bash:

'touch' is not recognized as an internal or external command, operable program or batch file.

You can either use the following command in command prompt (cmd):

echo. > .gitignore

or

type nul > .gitignore

as indicated here: Windows equivalent of 'touch' (i.e. the node.js way to create an index.html). This procedure will not generate a Text Document as indicated in the problem statement, but a file that appears to not have any extension.

Windows Explorer:

If you try to do it in Windows 10 Explorer by clicking right mouse button(RMB)>New>Text Document and you try to name it .gitignore you can receive the following error:

You must type a file name.

This can be overcome by giving it the filename .gitignore.. So if your git repository folder contains a folder named output which you want to suppress/not sync, you can add it to the .gitignore by editing the .gitignore. file with a text editor and adding a line that contains /output. This last procedure generates a file which is also a .txt document as indicated in the problem statement, but as mentioned by @hobbs and @Youkool that is not a problem for git. Furthermore, the last procedure is verified in Windows 10 with git version 2.16.1.windows.4.

a.t.
  • 2,002
  • 3
  • 26
  • 66
0

but when I looked at the file from the windows explorer. It says it's a text document. Isn't it supposed to be of the type File

Windows says your README is of type File because it has no extension. In contrast, your .gitignore file has the extension .gitignore which Windows has been configured to report (probably by the git-for-windows installer) the type Text Document.

Ben
  • 1,287
  • 15
  • 24
-1

Please refer to How do I manually create a file with a . (dot) prefix in Windows? For example, .htaccess.

Reproducing for your easy access: In File Explorer, right click anywhere and create a new file. Type the new filename as .something. (notice the appended period) and press Enter twice, job done.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
rajuat
  • 1
  • 1