60

After reading proper section of GitHub Help I got completely lost. It says:

This file can be committed into the repository, thus sharing the rule list with any other users that clone the repository.

Up until now, people I've been talking to about Git were telling me that ".gitingore file must be committed or else its rules won't work!"

Every Git begginer's question: "Why .gitignore rules are not applied?" Could be answered with a simple: "Did you commit it?".

And now, here comes the GitHub Help saying, that this file can be commited, but it isn't necessary

Neithan Max
  • 11,004
  • 5
  • 40
  • 58
trejder
  • 17,148
  • 27
  • 124
  • 216
  • 3
    Note that ignores that you *don't* want to share, e.g. specific configuration files for an IDE that only you use, can be ignored using `.git/info/exclude`. The format of this file is the same as `.gitignore`, but this file will never be committed. – ChrisGPT was on strike Feb 06 '14 at 13:08
  • 2
    Also, the contents of `.gitignore` take effect as soon as the file is created or modified. The "committed" question usually refers to *other files*. E.g., if you commit file `foo.c` and then add `foo.c` to `.gitignore`, it will *not* get ignored. Your ignores prevent files from being tracked initially, but once they become tracked the ignore file does nothing to them. – ChrisGPT was on strike Feb 06 '14 at 13:12

1 Answers1

72

Yes, you can track the .gitignore file, but you do not have to.

The main reason of having this file into repository is to have everyone working on the project, ignoring same files and folders.

Also see this: Should you commit .gitignore into the Git repos?

Giorgi Tsiklauri
  • 9,715
  • 8
  • 45
  • 66
e h
  • 8,435
  • 7
  • 40
  • 58
  • 4
    So my question is (again) a duplicate! :| Funny thing, that I found nothing similar, though (I think) I was searching quite deeply. Anyway, thank you for your contribution! – trejder Feb 06 '14 at 11:16
  • 14
    Well you were the top hit in the search results for me now so it seems you have gotten the SEO right. – Jesse Reza Khorasanee May 02 '19 at 23:43