There's more...

It's also possible to ignore files of a repository without the .gitignore files. You can put your ignored files in a global ignore file, for example ~/.gitignore_global, and globally configure Git to also consider entries in this file to be ignored:

$ git config --global core.excludesfile ~/.gitignore_global

You can also do it per repository in the .git/info/exclude file. If you use either of these options, you won't be able to easily share the ignored file; they can't be added to the repository as they are stored outside it. Sharing .gitignore files is much easier; you just add and commit them to Git. But, let's see how the other options work:

$ echo "*.test" > .git/info/exclude
$ touch test.test
$ git status
On branch ignore ...

Get Git Version Control Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.