67

I created a new Scala/sbt project in IntelliJ IDEA 13. Since other team members will be working on this project (presumably with other IDEs), what should I put in the .gitignore? It seems some of the project dependencies are defined in the .idea folder, so I wasn't sure if I can put the whole directory in .gitignore or not.

Jacek Laskowski
  • 72,696
  • 27
  • 242
  • 420
anshumans
  • 4,045
  • 2
  • 18
  • 25

2 Answers2

80

EDIT After discovering Joe:

Just ask Joe to take care of your .gitignore

Original Answer:

Since you're using Scala you should add:

target
*.class

These can be generated back easily and could be machine dependent.

If you're going to use IntelliJ then the following:

*.iml
*.ipr
*.iws
.idea
out

The .idea folder and the .iml files are created and used only by IntelliJ, other IDEs will just ignore them. They can be generated easily by IntelliJ if needed, try deleting your .idea folder and then open the project in IntelliJ and, lo and behold the first thing it does is generate the .idea folder and it's contents.

For Vim:

tags
.*.swp
.*.swo

For Eclipse(Scala IDE):

build
.classpath
.project
.settings
org.scala-ide.sdt.core/META-INF/MANIFEST.MF
org.scala-ide.sdt.update-site/site.xml`

For macOS:

.DS_Store

I think this covers the most popular IDEs for Scala. If someone's using an IDE not covered, you'll have to look around for what temporary and build files they create.

Jämes
  • 6,945
  • 4
  • 40
  • 56
aa333
  • 2,556
  • 16
  • 23
  • I've used the [gen-idea](https://github.com/mpeltonen/sbt-idea) plugin for sbt. I don't know if that can do more than IntelliJ alone. – ggovan Jun 19 '14 at 01:57
  • How do I ask Joe to take care of it? The tool doesn't seem to have any IntelliJ Idea support. – Asad Saeeduddin Aug 06 '15 at 07:00
  • 1
    @aa333 Did you mean `joe g jetbrains`? Without the g it doesn't work for me. Also, joe was rather difficult to configure and it seems to now have some dependency/backward-compatibility issues. (When I run it I get "deprecated cli app action signature... this is an error in the application.") – William DeMeo May 29 '16 at 18:17
  • that comment is obsolete after recent changes to `joe`. `joe g jetbrains` is the correct command with the most recent version. – aa333 May 30 '16 at 19:30
  • 2
    Should I add `project` into `.gitignore`? It seems to be auto-generated by SBT... – iBug Feb 26 '19 at 12:01
  • `joe` has been abandoned as of this comment and no longer works. – EML Apr 21 '19 at 01:19
37

Here's what gitignore.io suggests for Scala and sbt:

# Created by https://www.gitignore.io/api/sbt,scala

### SBT ###
# Simple Build Tool
# http://www.scala-sbt.org/release/docs/Getting-Started/Directories.html#configuring-version-control

dist/*
target/
lib_managed/
src_managed/
project/boot/
project/plugins/project/
.history
.cache
.lib/

### Scala ###
*.class
*.log

# End of https://www.gitignore.io/api/sbt,scala

I usually recommend putting IDE / editor ignores into .git/info/exclude if you've got a mix of editors. This is a personal ignore file that does not get committed with the repository.

gitignore.io has suggestions for IDEs and editors too:

ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257
  • Wonder what `project/boot/` is for in sbt? When does it get created? – Jacek Laskowski Jun 19 '14 at 09:21
  • @JacekLaskowski, I'm not sure. I only have passing experience with Scala. But [GitHub recommends exactly the same thing](https://github.com/github/gitignore/blob/master/Scala.gitignore) (I think that's where gitignore.io gets its ignore files from). – ChrisGPT was on strike Jun 19 '14 at 12:14
  • 1
    Found it in [Boot directory](http://www.scala-sbt.org/0.13.5/docs/Detailed-Topics/Setup-Notes.html#boot-directory): *"For example, the following uses the pre-0.11 style of putting the boot directory in project/boot/"*. It can since be simply removed. – Jacek Laskowski Jun 22 '14 at 06:50
  • IntelliJ itself recommends only ignoring few files from .idea directory: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839-How-to-manage-projects-under-Version-Control-Systems – Tautvydas Nov 28 '16 at 13:38
  • @Tautvydas, if there is a single mandated IDE it _might_ make sense to track certain IDE files. But if developers are free to use other tools I strongly prefer not to track IDE-specific files. It seems I'm not alone based on the gitignore.io recommendation in my answer. [`joe`](https://github.com/karan/joe) also recommends ignoring the entire `.idea/` directory, though it recognizes that some users may want to track some of its contents. Anyway, this is only a guideline. If you are confident that something else is a better fit for your project, go for it. – ChrisGPT was on strike Nov 28 '16 at 13:45