In less than 12 months, Drupal 7 will be end-of-life and no longer supported. Plan your upgrade to Drupal 10 now.

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

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

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

Both approaches work and are regularly used.

Which approach do you prefer and why?

Reply and let me know.

- Oliver

P.S. There's less than a year until Drupal 7's end-of-life date. Plan your upgrade to Drupal 10 now!

Was this useful?

Sign up here and get more like this delivered straight to your inbox every day.

About me

Picture of Oliver

I'm an Acquia-certified Drupal Triple Expert with 17 years of experience, an open-source software maintainer and Drupal core contributor, public speaker, live streamer, and host of the Beyond Blocks podcast.