681

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.

BuZZ-dEE
  • 6,075
  • 12
  • 66
  • 96
Borek Bernard
  • 50,745
  • 59
  • 165
  • 240
  • 16
    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. – chalimartines Aug 15 '12 at 11:57
  • 20
    @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. – Borek Bernard Aug 15 '12 at 12:20
  • Possible duplicate of [Intellij Idea 9/10, what folders to check into (or not check into) source control?](https://stackoverflow.com/questions/3041154/intellij-idea-9-10-what-folders-to-check-into-or-not-check-into-source-contro) – Cœur Jul 14 '18 at 14:15
  • In latest versions, there will be created an .gitignore files inside the .idea folder, what already contains a bunch of good ignore rules (to keep files that should be shared, and exclude user specific stuff) – Radon8472 Aug 24 '23 at 08:36

10 Answers10

552

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.

BuZZ-dEE
  • 6,075
  • 12
  • 66
  • 96
hifkanotiks
  • 5,915
  • 1
  • 17
  • 24
  • 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 – Kevin Ortman Dec 30 '12 at 20:38
  • @KevinOrtman this does not seem to work if the project is not at the root of your repository? – vsp Apr 04 '13 at 12:07
  • 9
    The correct syntax seems to be `*/.idea/workspace.xml */.idea/tasks.xml` – vsp Apr 04 '13 at 12:24
  • 1
    @KevinOrtman, the answer pertains to two different file formats. `*.iws` files are ignored when using the `.ipr` project format, and `workspace.xml` and `tasks.xml` files are ignored when using the `.idea` project format. – Jade Jun 22 '13 at 17:07
  • 2
    What about `.idea/watcherTasks.xml`? This file contains very user-dependent settings like paths to executables. – David Jul 25 '13 at 14:10
  • What to do if I'm the only person in team who is using Rubymine others are on Sublime Text? – Jitendra Vyas Jan 10 '14 at 15:39
  • 135
    A better syntax is `**/.idea/workspace.xml **/.idea/tasks.xml` – Josh Unger Feb 02 '14 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 '15 at 19:27
  • 2
    The updated official Jetbrains link is: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839-How-to-manage-projects-under-Version-Control-Systems – jpoveda Jan 05 '16 at 05:50
  • In my latest version of PHPStorm (2016.2.1) I'm getting a `.idea/copyright/` directory. So I now add a `**/.idea/copyright/` line to my `.gitignore`. – Snowcrash Sep 30 '16 at 13:57
  • I had to also exclude the file _.idea/vcs.xml_ for it to work. – trinity420 Apr 04 '17 at 20:15
  • Based on https://rider-support.jetbrains.com/hc/en-us/community/posts/115000661950-A-lot-of-files-in-contentModel-xml the contentModel file should also be ignored using **/.idea/contentModel.xml (I think that it is Rider specific). It contains absolute paths. – Harps Apr 26 '18 at 07:54
  • 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 '18 at 14:54
  • 1
    so you can share with coworkers project-wide settings like code style, folder types, etc – igorsantos07 Jun 06 '18 at 20:34
  • Note that since version 2019.1, IntelliJ can [automatically add the right config files to version control](https://www.jetbrains.com/help/idea/creating-and-managing-projects.html#share-project-through-vcs). – Antony Mativos Oct 22 '19 at 08:20
  • In can other extensions (like SonarLint) adds extra files to .idea, you can get a more targeted .gitignore like this: **/.idea/** !**/.idea/**/*.xml !**/.idea/**/*.iml **/.idea/workspace.xml **/.idea/tasks.xml – Doug May 10 '20 at 03:10
  • JetBrains now recommends to exclude the `shelf` folder and a file called `usage.statistics.xml` as well. – DerKanzler Feb 27 '21 at 08:12
329

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
GabrielOshiro
  • 7,986
  • 4
  • 45
  • 57
  • 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 '16 at 15:17
  • 3
    Why would you ignore `.idea/dictionaries` outright? –  Sep 10 '16 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. – GabrielOshiro Sep 12 '16 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. –  Sep 12 '16 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 https://intellij-support.jetbrains.com/hc/en-us/articles/206544839-How-to-manage-projects-under-Version-Control-Systems – nealmcb Jun 01 '17 at 15:03
53

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.

Frankie
  • 24,627
  • 10
  • 79
  • 121
  • 9
    That's exactly my point, We should not hassle around `.gitignore` just for JB as I have explained in my answer. – nehem May 13 '20 at 13:18
  • 1
    Somehow I ended up with a default .gitignore that would not simply excluding the whole .idea folder and my changes was often polluted with nonsense. Just ignore the whole folder. – Slion Jun 07 '23 at 09:49
32

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 
user229044
  • 232,980
  • 40
  • 330
  • 338
xgqfrms
  • 10,077
  • 1
  • 69
  • 68
  • 2
    OK! if you want to ingore something, you can go to [https://www.gitignore.io/](https://www.gitignore.io/ ) , it can be very helpful for you to easily find what you wanna! – xgqfrms Oct 01 '16 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. – Frankie Simon May 09 '17 at 07:50
  • 3
    Why not just do `.idea/*`? Saves a lot of lines. – Hackinet Jun 03 '21 at 03:09
  • @Hackinet that's depends on your situation, ignore all files with the `*` symbol or just only needs ignore some specials files. – xgqfrms Jun 04 '21 at 13:50
22

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
Cereal
  • 3,699
  • 2
  • 23
  • 36
16

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

craigcaulfield
  • 3,381
  • 10
  • 32
  • 40
DinoPi
  • 327
  • 2
  • 2
  • I disagree. When you do this, you exclude a.. runConfigurations too, so you can not share important tasks for building/minifing css ect. – Radon8472 Aug 24 '23 at 08:28
2

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

sasquad92
  • 45
  • 1
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.

Lucio
  • 4,753
  • 3
  • 48
  • 77
-1

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.

nehem
  • 12,775
  • 6
  • 58
  • 84
  • 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 05 '20 at 14:26
  • `/.idea` doesn't work, You can check other answers and the official guidelines from JB too – nehem May 06 '20 at 02:58
  • 4
    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. – Christopher Barber Jun 23 '20 at 14:53
  • @ChristopherBarber You don't understand because you haven't met with the problem yet. When I meant keeping gitignore clean I considered constantly changing it file for something not the fault of the developer just because Jetbrains keep adding files or changing filenames. – nehem Jun 24 '20 at 04:44
  • 3
    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. – Christopher Barber Jun 24 '20 at 14:38
  • While I relate to what you want to do just put `.idea` folder on .gitignore and be done with it. Using your solution, instead of "polluting" git' ignore file you are actually "polluting" your workspace with unnecessary folders just for the sake of using JetBrains. No need to do that! – Frankie Jun 24 '20 at 14:39
  • @ChristopherBarber adding `/.idea/` doesn't work as one imagines, otherwise numerous answers in this thread and other threads are simply vain. Even Jetbrains' recommend `.gitignore` list contains explicit list of individual `.xml` files. – nehem Jun 24 '20 at 16:59
  • I don't know what you imagine. But adding `/.idea` ignores all of the files in that directory. If that is what you want, you are done. If you only want to ignore some files, then you have to list them individually, but then your answer would also be useless. – Christopher Barber Jun 24 '20 at 20:04
  • I wouldn't recommend this approach either; it is much more of a burden than necessary. You can add `.idea` to your global Git ignore as mentioned in other comments, or just ignore `.idea` altogether, since the IDE now produces a `.gitignore` file in the `.idea` directory when it is created. – Aanand Kainth Jul 27 '20 at 18:53
  • You don't need this solution until you do. – nehem Jul 28 '20 at 00:24
  • 2
    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. – terrorrussia-keeps-killing Mar 14 '22 at 07:07
  • @user12232870 the amount of lines other people suggest to ignore for `.idea/` related files are indeed too untidy – nehem Mar 14 '22 at 08:26
  • The idea is quite nice, the only problem could be, if your project contains files that are expected to be in project root. E.g. composer.json – Radon8472 Aug 24 '23 at 08:26
-11
  • Remove .idea folder

    $rm -R .idea/
    
  • Add rule

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

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

Pang
  • 9,564
  • 146
  • 81
  • 122
Tai LE
  • 99
  • 3