.gitignore mistake that everyone makes

Gajus Kuizinas
1 min readSep 22, 2020

.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.

--

--

Gajus Kuizinas

Founder, engineer interested in JavaScript, PostgreSQL and DevOps. Follow me on Twitter for outbursts about startups & engineering. https://twitter.com/kuizinas