75

Unlike Netbeans, in Jetbrains IDEs, the setting files related to user and team are mixed in the same folder that makes it tricky when you need to push them to git.

There is a number of sample git ignore files for these IDEs and https://intellij-support.jetbrains.com/hc/articles/206544839 page on git site.

However, after using them for a months we figure out that it is safer and actually more convenient to do the reverse. I mean ignoring all .idea files and adding only team-related settings explicitly. (instead of adding all and ignoring some).

The main thing that can be shared among developers is code style configs. So, by using IDE auto-reformatting option all the team will follow a consistent style.

Besides that, the question is which other files are recommended to be included and not ignored? Why?

Answer: I came across with this: https://github.com/salarmehr/idea-gitignore

Jorge Gil
  • 4,265
  • 5
  • 38
  • 57
Handsome Nerd
  • 17,114
  • 22
  • 95
  • 173
  • 1
    This question already has the answer in [IntelliJ IDEA Knowledge Base](https://intellij-support.jetbrains.com/hc/articles/206544839). – CrazyCoder Apr 04 '17 at 09:38
  • 1
    @CrazyCoder Thanks for your comment. The page also describe which file should be ignored. But this method introduced trouble to my team. e.g. `.idea\watcherTasks.xml` can not be shared because the pathes to watcher differs among user. I need a guild to what each file do and how sharing it among team be be beneficial. – Handsome Nerd Apr 05 '17 at 01:33
  • I'm afraid, it's not documented anywhere with that level of detail. – CrazyCoder Apr 05 '17 at 08:25
  • IMO it is better to avoid committing these configurations into source control, you are just creating more problems than the benefit you get. There are just too many detail which can varies depends on your project & your team. To sync settings between developers, I would suggest create a document for setting up the project in IntelliJ IDEA. – Rangi Lin Apr 07 '17 at 04:58
  • The very basic fundamental of VCS is anyone can clone your repo, build and start working be it whatever IDE (not necessarily webstorm). If you commit you .idea files, you are type depending the code repo to be specific to your configs of webstorm. Why ? – pravs Apr 13 '17 at 19:40
  • 1
    @pravs committing `.idea` folder dose not prevents other with different IDE to build and run the project but may help you the subset of developers in team who use JetBrains ide share some settings. – Handsome Nerd Apr 13 '17 at 21:17

6 Answers6

55

Jetbrains has some official guidance on which files should not be checked in, and which files should probably not be checked in, depending on your usage. According to that page, you should check in all files in the .idea directory except:

  • workspace.xml
  • tasks.xml

And probably also:

  • the xml files in the dictionary subdirectory

While the particular answer may depend on your team's particular practices, in my experience, following that guidance generally results in correct separation of user settings and shared project configuration.

Some examples of files that should be shared, according to this guidance:

  • ant.xml, which, if you use Ant to build your project, points IDEA to your build files and configures properties that should be used to build.
  • vcs.xml, which specifies the Version Control configuration for your project
  • encodings.xml, which specifies how IDEA should treat the text files in your project
  • modules.xml, which points IDEA to each of your project's module configuration files, which should also be shared in your VCS.
  • all files under the runConfigurations subdirectory, which tells IDEA what it needs to do to run your application
  • codeStyleSettings.xml, which, as you have alluded to, puts your whole team on the same page in terms of automatic code formatting

Depending on your team's usage, there may be more or less, but those are some of the biggest examples.

Matthew Leidholm
  • 4,199
  • 3
  • 24
  • 26
  • 28
    I could not disagree more. I have been coaching development teams for 12+ years as an agile coach and never ever found it to be a good idea to commit IDE project info. All of this is not needed if you commit your Maven (or Gradle or whatever) configuration and make sure it gets imported into the IDE after clone/checkout. **Don't do it!** Don't commit IDE-related stuff. The only exception might be auto-format presets according to team convention, but as an importable config file in a separate folder for all team members, not directly in the `.idea` folder. – kriegaex Apr 16 '17 at 10:47
  • 1
    I usually follow that guidance, and having codeStyleSettings and runConfigurations shared along with the project is nice for teams. – FGM Sep 20 '18 at 11:08
  • Sure, Jetbrains has the official guide. But check several pages of comments under the article. It seems many people struggle with that. I'd recommend committing IDE files only if you know what you do. – Anton Belonovich Aug 07 '22 at 19:15
  • 1
    @kriegaex So how do special run configurations get shared (i.e., I dunno, aspectj, jvm options, etc. :))? every dev should set those up individually? I've unfortunately got multiple people on my team that can't follow simple directions. I don't want to have to babysit them through 75 IntelliJ tweaks. – SledgeHammer Nov 25 '22 at 19:45
  • 1
    I put everything I can into Maven and auto-import it, trying to be as little dependent on manual IDE settings as possible. If your team members cannot follow simple directions, educate them or look for new team members. Don't make them fools with tools. Empower them instead of treating them like kids. – kriegaex Nov 25 '22 at 21:39
15

After some investigation, I came up with https://github.com/salarmehr/idea-gitignore, so you create/modify .idea/.gitignore as below.

#### ignore all .idea files ...
*

#### except

# Version Control configuration for your project
!vcs.xml

# how IDEA should treat the text files in your project
!encodings.xml

# automatic code formatting
!codeStyleSettings.xml

# project specific words
!dictionaries

!copyrights
!misc.xml
!sqldialects.xml

Above files should practically be identical for all team members.

Handsome Nerd
  • 17,114
  • 22
  • 95
  • 173
  • 1
    Thank you. My use case is contributing to open-source projects. Those projects have contribution guide and nearly never mention `.idea` folder in `.gitignore`. After fighting Idea IDE to move `.idea` folder outside of the project, changing `.idea/.gitignore` to simply `* # ignore all .idea files ...` solves that. Thanks again for the insight. – darkless Sep 17 '20 at 19:48
14

I prefer not to check in the .idea folder or .iml files at all.

  • If you want to share editor styles, consider using a .editorconfig file, the JetBrains IDEs support these now.
  • For other things, like build settings you could try to lean on your build tool, e.g. use maven or gradle build files to carry specific setups.
  • Obviously there's a bunch of other things that won't be covered, but most of them can be solved by well documented conventions.
ninj
  • 1,529
  • 10
  • 10
  • Thanks ninj for suggesting .editorconfig, yet it does not cover all phpstrom code formating capabilities. – Handsome Nerd May 04 '17 at 04:36
  • if need additional code formatting enforcement you can use build tools to reformat code, e.g. https://prettier.io/ and friends. If they run fast enough then you can also use them as part of a pre-commit hook! – ninj Dec 22 '20 at 21:22
  • You're unfortunately assuming that people can follow long docs explaining setting up a bunch of settings (and possibly screwing some up along the way). – SledgeHammer Nov 25 '22 at 19:48
  • If your team is using a CI server then that can force formatting as a check too. – ninj Nov 26 '22 at 19:25
  • I think you are right, many inexplicable errors can work normally after deleting `.idea` and rebuild. – SageJustus Mar 23 '23 at 03:20
6

I use both IDEA and Eclipse, but not Netbeans. I never commit any project files but make sure that I have a Maven build as the leading tool, then I can easily import the Maven project into any IDE with Maven support and also refresh from Maven once I change it. For Eclipse and IDEA this works beautifully.

My .gitignore file looks like this for all of my projects:

# Eclipse
.settings/
.classpath
.project

# IntelliJ IDEA
.idea/
*.iml

# Maven
target/

Plus other, project-specific files or directories.

kriegaex
  • 63,017
  • 15
  • 111
  • 202
3

It's recommended not to commit all the .idea folder because it's for configurations. Like the *.iml file.

If I use Netbeans instead of Intellij, I don't want these config files. It is useless and maybe a little dangerous for conflicts.

YoannFleuryDev
  • 914
  • 1
  • 12
  • 22
0

What I do, regardless of which IDE, technology, or repository I use, I simply go to gitignore.io and enter the technology or IDE in the box to generate me the .gitignore file.

Then if I dont use git, I will check what is in this file and add it into the repository ignore list (for example SVN) and commit it to remote.

If I use git, then I just copy this file into my repo, stage, commit, and push it to remote.

pixel
  • 9,653
  • 16
  • 82
  • 149