.gitignore mistake that everyone makes

.gitignore should be a whitelist, not a blacklist of files you want to include.

If we look at a bunch of random open-source projects, they all instead try to exclude every known undesirable file, e.g.

This setup means that whenever a new developer joins the team or a new tool is adopted by someone in a team, you need to update .gitignore configuration.

A better solution is “ignore everything with exclusions”. In practice, this means that you ignore all files (or at least all hidden files) by default and add exceptions to those files that were agreed to be added to the project, e.g.

coverage
dist
node_modules
package-lock.json
*.log
.*
!*/*.babelrc.js
!.dockerignore
!.editorconfig
!.eslintignore
!.eslintrc
!.gitignore
!.gitlab-ci.yml
!.npmignore
!.storybook
!.npmrc
!.prettierignore

In this project we are ignoring all files that start with a dot, but we’ve added exceptions to the configuration files that belong to the project.

This configuration also ensures that you do not accidentally commit private files (keys) that are conventionally prefixed with a dot too.

Adopting this convention will save back-and-forth discussing what exclusions should be added to .gitignore.

Written by

Software architect, startup adviser. Editor of https://medium.com/applaudience. Founder of https://go2cinema.com.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store