667

Possible Duplicate:
Intellij Idea 9/10, what folders to check into (or not check into) source control?

I started using WebStorm for web development and am not sure what to add and what to exclude from our Git repository. Clearly some files inside the .idea folder are meant to be version controlled like the external library settings (jsLibraryMappings.xml) but others will probably change very often and are developer-specific (e.g., workspace.xml).

What is the recommended .gitignore pattern for WebStorm / IntelliJ IDEA?

P.S. There are already questions about this but usually focus only on whether to include the whole .idea folder or whether to fully exclude it. I think some of the files inside the .idea folder should be version controlled while others shouldn't and I'm trying to find out which ones.

3
  • 15
    I think, that put IDE files into versioning system is bad idea. Your project will be more tied to particular IDE and you can bring problems for users of other IDEs. I had a few projects with IDE files in VCS and I faced complications. Now I have in VCS just maven files and IDEA generate project files and everything is fine. Aug 15, 2012 at 11:57
  • 17
    @chalimartines I prefer to have everything required for build in the repository. As we don't use Maven and also use a single IDE, it would be a complication NOT to have .idea files in VCS. Aug 15, 2012 at 12:20

10 Answers 10

541

The official support page should answer your question.

So in your .gitignore you might ignore the files ending with .iws, and the workspace.xml and tasks.xml files.

17
  • 8
    The doc recommends "share all the .iml module files", so a .gitignore with the following two lines should be fine: .idea/workspace.xml .idea/tasks.xml Dec 30, 2012 at 20:38
  • 9
    The correct syntax seems to be */.idea/workspace.xml */.idea/tasks.xml
    – vsp
    Apr 4, 2013 at 12:24
  • 130
    A better syntax is **/.idea/workspace.xml **/.idea/tasks.xml
    – Josh Unger
    Feb 2, 2014 at 15:28
  • 4
    I generally ignore the entire folder - seeing as I am pretty much the only one that uses such an IDE in my workplace.
    – klidifia
    Feb 24, 2015 at 19:27
  • 4
    What's the benefit of committing the idea folder? I will just continue ignoring it after reading two more additions of files that need ignored unless someone can give me a good reason to keep it version controlled.
    – Lo-Tan
    May 24, 2018 at 14:54
317

I just want to present a more recent alternative. There is an online tool that generates .gitignore files based on operating systems, IDEs and programming languages that you might be using.

gitignore.io


EDIT Disclaimer: Do not copy this file, copy the file generated by the website instead, they do a good job on keeping it updated. This is just an example.

The file generated for IntelliJ contains the following

# Created by https://www.gitignore.io/api/intellij

### Intellij ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# User-specific stuff:
.idea/workspace.xml
.idea/tasks.xml
.idea/dictionaries
.idea/vcs.xml
.idea/jsLibraryMappings.xml

# Sensitive or high-churn files:
.idea/dataSources.ids
.idea/dataSources.xml
.idea/dataSources.local.xml
.idea/sqlDataSources.xml
.idea/dynamic.xml
.idea/uiDesigner.xml

# Gradle:
.idea/gradle.xml
.idea/libraries

# Mongo Explorer plugin:
.idea/mongoSettings.xml

## File-based project format:
*.iws

## Plugin-specific files:

# IntelliJ
/out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties

### Intellij Patch ###
# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721

# *.iml
# modules.xml
5
  • 1
    "By default they suggest you ignore everything from .idea/" - not any more. Currently generated .gitignore doesn't have the .idea/ entry.
    – Mikolaj
    May 31, 2016 at 15:17
  • 3
    Why would you ignore .idea/dictionaries outright?
    – user824425
    Sep 10, 2016 at 14:11
  • @Rhymoid I don't know why specifically since I am not the one proposing the .gitignore. I am just showing the tool that does it. My guess is that it is a personal file. You can add stuff in your dictionary that might not be valid for others. Specially when you are cleaning up LINT messages. I believe that if you agree amongst your teammates you might add it to your git repo. Sep 12, 2016 at 15:00
  • 4
    I intended to use the generic 'you', sorry. But with the parallels it has to linting, it totally makes sense to have them in a source repo, because the entries will in fact apply to everyone: the dictionaries are specific to the content of the project! For instance, when working on a parser for C, everyone will run into the problem that the word "punctuator" is falsely marked as a misspelling... unless you share the dictionary.
    – user824425
    Sep 12, 2016 at 18:37
  • @user824425 IntelliJ says to be careful about the user dictionaries folder (to avoid conflicts if other developer has the same name) - see intellij-support.jetbrains.com/hc/en-us/articles/…
    – nealmcb
    Jun 1, 2017 at 15:03
47

For a couple of years I was a supporter of using a specific .gitignore for IntelliJ with this suggested configuration.

Not anymore.

IntelliJ is updated quite frequently, internal config file specs change more often than I would like and JetBrains flagship excels at auto-configuring itself based on maven/gradle/etc build files.

So my suggestion would be to leave all editor config files out of project and have users configure editor to their liking. Things like code styling can and should be configured at build level; say using Google Code Style or CheckStyle directly on Maven/Gradle/sbt/etc.

This ensures consistency and leaves editor files out of source code that, in my personal opinion, is where they should be.

1
  • 8
    That's exactly my point, We should not hassle around .gitignore just for JB as I have explained in my answer.
    – nehem
    May 13, 2020 at 13:18
31

https://www.gitignore.io/api/jetbrains

Created by https://www.gitignore.io/api/jetbrains

### JetBrains ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# User-specific stuff:
.idea/workspace.xml
.idea/tasks.xml
.idea/dictionaries
.idea/vcs.xml
.idea/jsLibraryMappings.xml

# Sensitive or high-churn files:
.idea/dataSources.ids
.idea/dataSources.xml
.idea/dataSources.local.xml
.idea/sqlDataSources.xml
.idea/dynamic.xml
.idea/uiDesigner.xml

# Gradle:
.idea/gradle.xml
.idea/libraries

# Mongo Explorer plugin:
.idea/mongoSettings.xml

## File-based project format:
*.iws

## Plugin-specific files:

# IntelliJ
/out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties

### JetBrains Patch ###
# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721

# *.iml
# modules.xml
# .idea/misc.xml 
# *.ipr 
4
  • 2
    OK! if you want to ingore something, you can go to [gitignore.io/](https://www.gitignore.io ) , it can be very helpful for you to easily find what you wanna!
    – xgqfrms
    Oct 1, 2016 at 20:56
  • 1
    This is helpful but it would better if you just linked to the file - there are already differences in the online version. May 9, 2017 at 7:50
  • 3
    Why not just do .idea/*? Saves a lot of lines.
    – Hackinet
    Jun 3, 2021 at 3:09
  • @Hackinet that's depends on your situation, ignore all files with the * symbol or just only needs ignore some specials files.
    – xgqfrms
    Jun 4, 2021 at 13:50
21

Github uses the following .gitignore for their programs

https://github.com/github/gitignore/blob/master/Global/JetBrains.gitignore

# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf

# Generated files
.idea/**/contentModel.xml

# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml

# Gradle
.idea/**/gradle.xml
.idea/**/libraries

# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn.  Uncomment if using
# auto-import.
# .idea/modules.xml
# .idea/*.iml
# .idea/modules

# CMake
cmake-build-*/

# Mongo Explorer plugin
.idea/**/mongoSettings.xml

# File-based project format
*.iws

# IntelliJ
out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Cursive Clojure plugin
.idea/replstate.xml

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties

# Editor-based Rest Client
.idea/httpRequests

# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser
0
14

You can simply ignore all of them by adding .idea/* to the .gitignore file.

0
1

in my case /**/.idea/* works well

0
1

As stated in the support page, starting with version 2019.1, IntelliJ is capable of adding everything that needs sharing to Version Control automatically.

This is great since the IDE will add just the necessary files to Git in two steps:

  1. Open the project with IntelliJ and wait a moment until the following pop to shows up in the bottom-right corner
  2. Select "Always Add"

IntelliJ menu pop-up says "Project configurations files can be added to Git"

Alternatively you can select "View Files" and then add them manually.

-2

While maintaining the proper .gitignore file is helpful, I found this alternate approach is way cleaner and easier to use.

  • Create dummy folder my_project and inside that git clone my_real_project the actual project repo.
  • Now while opening the project in IDE (Intellij/Pycharm) open the folder my_project and mark my_project/my_real_project as the VCS root.
  • You can see my_project/.idea wouldn't pollute your git repo because it happily lives outside the git repo which is what you want. This way your .gitignore files stays clean as well.

This approach works better due to the below reasons.

1 - .gitignore file stays clean and we don't have to insert lines related to JetBrains products, that file is better used for binaries and libraries and autogen contents.

2 - Intellij keeps updating their projects and the files inside .idea keep changing every significant release from JB. What this means is we have to keep updating our .gitignore accordingly which is not an ideal use of time.

3 - Intellij has the flawed pattern here, most editors Atom, VS Code, Eclipse... nobody stores their IDE contents right inside project root. JB shouldn't be an exception either. It's the onus of Jetbrains to keep those files tracked outside project root. They have to refrain from polluting VCS root. This approach does just that. The .idea folder is kept outside the PROJECT_ROOT

Hope this helps.

12
  • 5
    This answer is completely misleading. /.idea in .gitignore works fine; Usually the problem will be solved after by this command: git rm --cached -r .idea
    – HosseyNJF
    May 5, 2020 at 14:26
  • /.idea doesn't work, You can check other answers and the official guidelines from JB too
    – nehem
    May 6, 2020 at 2:58
  • 3
    I don't understand why you think you need to keep your .gitignore clean. But you can always just put this in your user git config rather than going through this extra dummy folder approach. Jun 23, 2020 at 14:53
  • 2
    Yes, but if you want to ignore all of the .idea files you only need to add /.idea/ to your .gitignore file once and forget about it. Or you can do the same thing in your user .gitconfig and not bother with this dummy folder approach. Jun 24, 2020 at 14:38
  • 1
    No idea why this one got downvoted. I totally agree that IDE stuff must never be .gitignore-d and committed to the repository just because someone thinks this is the only IDE in use for this particular project. What if someone prefers Eclipse? .gitignore should only contain files that can be generated during the build, not ones that cover someone else's preferences for IDE. To all of the downvoters, learn what .git/info/exclude and core.excludesfile are. Mar 14, 2022 at 7:07
-9
  • Remove .idea folder

    $rm -R .idea/
    
  • Add rule

    $echo ".idea/*" >> .gitignore
    
  • Commit .gitignore file

    $git commit -am "remove .idea"
    
  • Next commit will be ok

6
  • 8
    ignoring the idea folder is fine as not everyone uses them, and they are not part of your code - you (hopefully) don't need them on production, for instance. Dec 13, 2017 at 21:15
  • 4
    ignoring is fine, but removing is less of a good idea. It contains information for your local workspace.
    – foo
    Mar 2, 2019 at 17:03
  • 1
    I'm surprised this is down-voted. Seams to be the best answer here! Mar 26, 2020 at 11:57
  • 2
    The answer is downvoted because it doesn't answer the question. You also don't have to remove your .idea folder in order to gitignore it. Jun 23, 2020 at 14:55
  • @ChristopherBarber you need to remove it from git origin though
    – aeracode
    Jan 22, 2021 at 14:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.