Android studio - should the entire .idea directory be in git ignore?

dors picture dors · Oct 13, 2014 · Viewed 61.2k times · Source

I saw a lot of examples for .gitignore files for AndroidStudio, some have .idea in them, and some don't.

Is there a good reason not to add the entire .idea dir to .gitignore?

If it should not be completely ignored, are there specific files inside .idea (such as .iml) that should be in .gitignore?

Answer

mithrop picture mithrop · Oct 13, 2014

You can take a look at this page :

IntelliJ doc about project configuration files

In the "Directory-based format", a particular line is interesting :

The .idea directory contains a set of configuration files (.xml). Each file contains only a portion of configuration data pertaining to a certain functional area which is reflected in the name of a file, for example, compiler.xml, encodings.xml, modules.xml.

Almost all of the files contain information core to the project itself, such as names and locations of its component modules, compiler settings, etc. Thus, these files may (and should) be kept under version control.

However, I properly HATE to make project IDE-dependent (I am currently working on a project made with NetBeans and it hurts to use it with Eclipse which becomes the standard of my company).

So, to answer your question :

  1. If you do not use something like Maven or Gradle to manage dependencies and build : keep the directory under version control. This way, the correct configuration of the project and dependencies will be available for everyone. In the counterpart, all developers will have to set their environment exactly the same way that you define it in the config files.
  2. If you do use something like Maven or Gradle : correctly configure these tools and do not keep the directory under version control. Actually, all the information contained inside config files should be stored in Maven/Gradle files. Then let your developers configure their IDE depending of their environment. This way, using Eclipse, IntelliJ, Linux, Windows ... will not be a problem anymore.