DEV Community

Oliver Davies
Oliver Davies

Posted on • Originally published at oliverdavies.uk on

gitignore - inclusive or exclusive?

Add everything and ignore what you don't want, or ignore everything and explicitly add what you need.

There are two ways to structure a .gitignore file.

The default approach is that all files can be added, and you specify the files and directories you want to ignore.

For example, if my .gitignore file was this, these two directories would be ignored:

vendor
web

Enter fullscreen mode Exit fullscreen mode

The other approach is to ignore everything and unignore the things to add. For example:

*
!build.yaml
!Dockerfile
!docker-compose.yaml
!web/*/custom

Enter fullscreen mode Exit fullscreen mode

Both approaches work and are regularly used.

Which approach do you prefer and why?

Reply and let me know.

P.S. Are you still using Drupal 7 and don’t know what’s involved to upgrade to Drupal 10? Book a Drupal 7 upgrade consultation call or an upgrade roadmap.

Top comments (0)