0

Any time I see a .gitignore file in a Git repository, I can't help but notice that, aside from the file extension, the filename is completely empty. Because of this, I've often seen new programmers run into the "You must enter a filename" error on Windows when learning Git for the first time.

Other standard files such as README.md include basenames, so it seems odd to exclude the name for .gitignore.

Is there a reason .gitignore's basename is always empty? Would the file still work properly if it were given a filename like project-name.gitignore?

4
  • 4
    filenames with . in front are a convention for "hidden" files on unix. .gitignore can be viewed like a hidden file with no extension. Windows doesn't approve of it much though. Commented Nov 7, 2017 at 15:14
  • I think just to hide the file from normal user, So that user does not change it by mistake. Commented Nov 7, 2017 at 15:42
  • 2
    See What are dot-files? on Ask Ubuntu for more examples. Commented Nov 7, 2017 at 16:01
  • I view .gitignore as a file name with no extension. If it had an extension, it would be, e.g., .gitignore.txt. But what is the extension of a file named a.b.c.d.e? Is it d.e, or b.c.d.e? It's clearly not .e: that would be silly! :-) Commented Nov 7, 2017 at 19:04

1 Answer 1

1

As stated by others in the comments, a dot in front of a filename implies a hidden file in unix/linux systems.

Would the file still work properly if it were given a filename like project-name.gitignore?

No, it would not. Git only looks for file named .gitignore (plus your global ignore file defined in config).

Other standard files such as README.md include basenames, so it seems odd to exclude the name for .gitignore.

README.md is not a standard file in Git, it is something that many hosting providers use. Standard git files such as .gitignore and .gitattributes have a consistent naming convention.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.