What to gitignore from the .idea folder?
GitIntellij IdeaGitignoreWebstormGit Problem Overview
> 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.
Git Solutions
Solution 1 - Git
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.
Solution 2 - Git
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.
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
Solution 3 - Git
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.
Solution 4 - Git
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
Solution 5 - Git
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
Solution 6 - Git
You can simply ignore all of them by adding .idea/*
to the .gitignore
file.
Solution 7 - Git
in my case /**/.idea/*
works well
Solution 8 - Git
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:
- Open the project with IntelliJ and wait a moment until the following pop to shows up in the bottom-right corner
- Select "Always Add"
Alternatively you can select "View Files" and then add them manually.
Solution 9 - Git
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 thatgit clone my_real_project
the actual project repo. - Now while opening the project in IDE (Intellij/Pycharm) open the folder
my_project
and markmy_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.
Solution 10 - Git
-
Remove .idea folder
$rm -R .idea/
-
Add rule
$echo ".idea/*" >> .gitignore
-
Commit .gitignore file
$git commit -am "remove .idea"
-
Next commit will be ok