Scala on IntelliJ with Git: How should the .gitignore look like?

Assuming that you're using SBT to build your project in IntelliJ, you should filter out the following directories:

project/target/
target/

(Actually, just adding target/ filters both out.)

These directories contain SBT output generated from your sources, and should not be placed under version control.

If everyone working on your project is to use IntelliJ while working on the code, then you should add all of the ./.idea directory with the following exceptions:

.idea/.name
.idea/libraries/
.idea/modules/
.idea/modules.xml
.idea/scala_compiler.xml
.idea/tasks.xml
.idea/workspace.xml
.idea_modules/

(You might also want to consider adding .idea/sbt.xml to this list. It has some redundant information from SBT, but some IntelliJ SBT configuration settings as well. Up to you...)

These files and directories either contain information gleaned by IntelliJ from SBT (and are, therefore, redundant) or contain machine- and/or user-specific information which will create problems if checked out on a different machine or by a different user.

If SBT is the primary build tool, and people can use any IDE they like, it would probably be better to ignore the entire .idea directory instead.


I would recommend using the website https://gitignore.io where it will build you a .gitignore file based on your environment.

Here's one that ignores everything you shouldn't commit for a Scala/SBT/Windows/Vim based project:

https://gitignore.io/api/git,sbt,scala,windows,intellij,vim