For IntelliJ IDEA, PyCharm, WebStorm, GoLand, Rider and the other JetBrains IDEs, ignore the per-user files inside .idea/ (workspace.xml, tasks.xml, usage.statistics.xml, shelf/, local data sources) and keep the rest. Those are the key lines of the tool’s JetBrains IDEs template, which has 28, including out/ for IntelliJ’s build output and cmake-build-*/ for CLion’s.
What it ignores, and what it keeps
JetBrains’ own advice is to share the .idea folder except the files that hold one person’s state, and the template follows it:
- Ignored: window layout and history (
workspace.xml,tasks.xml,*.iws), shelved changes, your spelling dictionary, local database connections (dataSources/,dataSources.local.xml), HTTP client requests, andgradle.xmlandlibraries/, which the IDE rebuilds on every Gradle or Maven import. - Kept:
codeStyles/,inspectionProfiles/,runConfigurations/,vcs.xmland the other project files, so everyone formats, inspects and runs the code the same way.
In a scratch repository with this file, git check-ignore -v -n --no-index names the line that matched each path, or prints :: when none did:
.gitignore:3:.idea/**/workspace.xml .idea/workspace.xml
.gitignore:7:.idea/**/shelf .idea/shelf/x.patch
.gitignore:13:.idea/**/dataSources.local.xml .idea/dataSources.local.xml
:: .idea/codeStyles/Project.xml
:: .idea/runConfigurations/App.xml
:: .idea/vcs.xml
.gitignore:18:.idea/**/gradle.xml .idea/gradle.xml
.gitignore:30:out/ out/production/x.class
:: sub/.idea/workspace.xml
.idea/**/workspace.xml matches .idea/workspace.xml because **/ can stand for no folders at all. The .idea/ prefix anchors every line to the root, so a project opened from sub/ is left alone.
A shared dictionary
.idea/**/dictionaries excludes the folder, and Git never looks inside an excluded folder, so !.idea/dictionaries/project.xml after it changes nothing; the file is still reported against line 6. Ignore the folder’s contents instead, .idea/dictionaries/* in place of that line, and the same ! line keeps the project dictionary:
.gitignore:36:!.idea/dictionaries/project.xml .idea/dictionaries/project.xml
.gitignore:6:.idea/dictionaries/* .idea/dictionaries/me.xml
out/ matches at any depth
out/ also hides a source folder called out, such as src/out/Printer.kt. IntelliJ writes out/ at the project root, so if you have one, anchor the line as /out/.
workspace.xml committed already?
.gitignore only affects untracked files. Untrack it, keeping it on disk, and commit:
git rm --cached .idea/workspace.xml
git commit -m "Stop tracking workspace.xml"
Ignoring all of .idea instead
Plenty of teams ignore the whole folder and share formatting through .editorconfig. That works, but put .idea/ in the project’s file, not your global ignore file: a global .idea/ would also hide shared run configurations in projects that commit them. The global file is the place for .DS_Store and Thumbs.db:
git config --global core.excludesFile ~/.gitignore_global