foo::bar

Blogs and RSS are cooler than ever

Stop polluting .gitignore files

Here is a .gitignore file generated by IntelliJ IDEA:

target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/

### IntelliJ IDEA ###
.idea/modules.xml
.idea/jarRepositories.xml
.idea/compiler.xml
.idea/libraries/
*.iws
*.iml
*.ipr
out/
!**/src/main/**/out/
!**/src/test/**/out/

### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
bin/
!**/src/main/**/bin/
!**/src/test/**/bin/

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/

### VS Code ###
.vscode/

### Mac OS ###
.DS_Store

### Scala ###
.bsp/

Similar exclusion patterns can be found in many projets, and even in files spit out by front-end project generators. They share the same issues:

  • They deal with items that are irrelevant to the project.

  • They are bound to be incomplete: where are the exclusions for vim, emacs, kwrite?

  • As a result, the are cluttered and the artefacts generated by the project are not clearly advertised.

Files generated by IDEs and editors are to be ignored on the computer, care of the developer, rather than in the repository. This can be achieved with a global .gitignore file. For instance:

$ cat ~/.gitignore_global

.vscode
.idea
*.iml
*.swp
.DS_Store

Do not forget to set up the global core.excludesfile

git config --global core.excludesFile '~/.gitignore_global'

I’d rewrite the .gitignore like so:

target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/
.bsp/