As a dev, do you use .gitignore to ignore everything and purposefully include? Or do you just exclude with it?

The second method is the best practice, when it comes to exlude some folder contents of gitignore rules.

It better reflect the following rule:

It is not possible to re-include a file if a parent directory of that file is excluded.

To exclude files (or all files) from a subfolder of an ignored folder f, you would do:

f/**
!f/**/
!f/a/sub/folder/someFile.txt

Meaning: you need to whitelist folders first, before being able to exclude from gitignore files.

It is clearer, shorter (unless you have a large number of folder to whitelist)

What if it is a Joomla install with a large amount of directories and files?
Or what if a core upgrade adds new files or folders

Don't forget you can have multiple gitignore files, one per folder.
That means you can mix and match both approaches.

And you have:

  • http://gitignore.io/ (which does blacklist when it comes to Joomla application)
  • github/gitignore (same approach for Joomla)

Tags:

Gitignore