204

I use Rubymine for Rails projects. Very often, Rubymine makes changes in .idea/* files that I don't care about. But it keeps preventing me from checking out new branches, and makes my version of .idea/ different from my coworkers.

We already added .idea/ to .gitignore, but it keeps tracking changes in .idea. How should I do this the right way?

Below is one of typical error messages I got:

error: Your local changes to the following files would be overwritten by checkout:
    .idea/workspace.xml
Promise Preston
  • 24,334
  • 12
  • 145
  • 143
AdamNYC
  • 19,887
  • 29
  • 98
  • 154

20 Answers20

339

Try git rm -r --cached .idea in your terminal. It disables the change tracking.

Petr Syrov
  • 14,689
  • 3
  • 20
  • 30
  • 2
    Thanks alot! But why its in the cache after i checkout a totaly empty repository? – Budi Sep 14 '17 at 22:34
  • 1
    Thank you, extremely useful. Used this to remove the files then added .idea to the gitignore and it worked great. Thank you so much! – Tim R Feb 14 '18 at 13:00
  • That doesn't really work when the .idea folder is already under tracking – ACV Jan 28 '19 at 09:45
  • 2
    So if the folder is already being tracked in Git, adding the .idea/ to .gitignore won’t stop Git from tracking it. You’ll need to do "git rm -r --cached .idea" first, then add .idea/ to your .gitignore. This will great to me. – Sam003 Apr 02 '19 at 20:35
284

just .idea/ works fine for me

the_joric
  • 11,986
  • 6
  • 36
  • 57
  • 5
    hi there! wanna tell us more how u do it...ain't working for me? :( – YoniGeek Nov 22 '13 at 13:10
  • Git works a bit differently than that. See the [git man page](http://git-scm.com/docs/gitignore#_pattern_format) for more info. – Steve Benner Jan 17 '14 at 13:34
  • This does work but does not work for sub-folders. For example I have 2 projects under the same Git and doesn't block either of them unless I add 2 lines "FolderA/.idea/" and "FolderB/.idea/" – Brad Bird Oct 13 '14 at 08:18
  • 6
    @BradBird I just tried it - works for subfolders as well. Also you may want to give a try to `**/.idea/` – the_joric Oct 13 '14 at 12:15
  • @the_joric What does the double asterix do? – Brad Bird Oct 13 '14 at 20:28
  • @BradBird it means match in all directories. – the_joric Oct 15 '14 at 14:31
  • 25
    Part of the issue is if you've already staged your stuff, the .gitignore will not help. – Dan Rosenstark Oct 16 '14 at 04:23
  • 14
    But if you want to ignore files/folders after you added/checked in them then you need to remove them with "git rm -r --cached web/uploads" (in this example i added "web/uploads" folder to .gigignore file after they were checked in) source: https://help.github.com/articles/ignoring-files/ – Dung Jan 28 '16 at 20:45
  • 2
    @DanRosenstark thank you! this was what was wrong in my case... everyone should check this before looking at their .gitignore file – CptKicks Jan 14 '21 at 01:22
43

Note that JetBrains recommends "If you decide to share IDE project files with other developers...", tracking all the .idea/* files except for the following:

  • workspace.xml
  • usage.statistics.xml
  • tasks.xml
  • the shelf/ directory

So to follow their advice, you would add those to your .gitignore.


Source:

If you decide to share IDE project files with other developers, follow these guidelines:
...
Here is what you need to share:

  • All the files under .idea directory in the project root except the workspace.xml, usage.statistics.xml, and tasks.xml files and the shelf directory which store user specific settings
  • ...

How to manage projects under Version Control Systems (archive)

There's some additional notes and discussion on that page that you should read if you're considering going ahead with this,
including additional files you may want to gitignore even if you decided you want to share IDE files (e.g. .iml files, .idea/modules.xml, gradle.xml, user dictionaries folder, additional files that are generated from gradle or maven).

Daryn
  • 4,791
  • 4
  • 39
  • 52
  • 13
    While I agree with this answer [+1'd for correctness], I *think* teams who aren't strict with IDEs and such can get away with not checking in the `.idea` folder at all... It's never made sense to me anyway, files in there always conflict for reasons that make no sense. – JaKXz Sep 07 '14 at 08:26
  • 7
    It is a bad practice to commit IDE specific files. One reason is that different developers may use different tools. Another one is that those files may contain user specific configuration which will get conflict all the time. – Jordan Silva May 02 '16 at 09:40
  • 3
    This recommendation is a bad practice. Using it in a project is the best way to version files that contain user specific information such as absolute path... Just look inside your `.idea` folder before following this reco. – JBE Jan 05 '17 at 17:22
  • 2
    While I would agree that _blindly_ committing IDE files is always a bad idea that is because blindly committing anything is a bad idea. In some circumstances sharing IDE files may work well. It is conceptually similar to sharing container orchestration files in that they are one way to run applications. Just like IDE files are one way to develop the project and can contain useful definitions like how to run the unit tests or code coverage commands, neatly wrapped up for a specific IDE. Most of the `.idea` files (in PyCharm at least) are designed to be shared. – Samuel Harmer Mar 18 '19 at 15:30
29

if a file is already being tracked by Git, adding the file to .gitignore won’t stop Git from tracking it. You’ll need to do git rm the offending file(s) first, then add to your .gitignore.

Adding .idea/ should work

appsmatics
  • 669
  • 9
  • 10
29

Add .idea/* to your exclusion list to prevent tracking of all .idea files, directories, and sub-resources.

Perception
  • 79,279
  • 19
  • 185
  • 195
24

using git rm -r --cached .idea in your terminal worked great for me. It disables the change tracking and unset a number of files under the rubymine folder (idea/) that I could then add and commit to git, thus removing the comparison and allowing the gitignore setting of .idea/ to work.

GMarx
  • 473
  • 3
  • 13
14

Close PHP Storm in terminal go to the project folder type

git rm -rf .idea; git commit -m "delete .idea"; git push;

Then go to project folder and delete the folder .idea

sudo rm -r .idea/

Start PhpStorm and you are done

Gustavo Maimone
  • 140
  • 1
  • 5
13

While it's not been too long that I made the switch to Rubymine, I found it challenging ignoring .idea files of Rubymine from been committed to git.

Here's how I fixed it

If you've not done any staging/commit at all, or you just spinned up a new project in Ruby mine, then simply do this

Option 1

Add the line below to the .gitignore file which is usually placed at the root of your repository.

# Ignore .idea files
.idea/

This will ensure that all .idea files are ignored from been tracked by git, although they will still remain in your project folder locally.

Option 2

If you've however done some staging/commit, or you just opened up an existing project in Ruby mine, then simply do this

Run the code in your terminal/command line

git rm -r --cached .idea

This deletes already tracked .idea files in git

Next, include .idea/ to the .gitignore file which is usually placed at the root of your repository.

# Ignore .idea files
.idea/

This will ensure that all .idea files are ignored from been tracked by git, although they will still remain in your project folder locally.

Option 3

If you've however done some staging/commit, or you just opened up an existing project in Ruby mine, and want to totally delete .idea files locally and in git, then simply do this

Run the code in your terminal/command line

git rm -r --cached .idea

This deletes already tracked .idea files in git

Run the code in your terminal/command line

rm -r .idea

This deletes all .idea files including the folder locally

Next, include .idea/ to the .gitignore file which is usually placed at the root of your repository.

# Ignore .idea files
.idea/

This will ensure that all .idea files are ignored from been tracked by git, and also deleted from your project folder locally.

That's all

I hope this helps

Promise Preston
  • 24,334
  • 12
  • 145
  • 143
12

In the rubymine gui, there is an ignore list (settings/version control). Maybe try disabling it there. I got the hint from their support guys.

enter image description here

Sparhawk
  • 1,581
  • 1
  • 19
  • 29
manavortex
  • 121
  • 2
9

Add .idea to ~/.gitignore_global and follow the instructions here to get .gitignore_global working:

Git global ignore not working

Then you don't have to ever add it to an individual .gitignore file.

Community
  • 1
  • 1
fosrias
  • 211
  • 1
  • 3
  • 7
5

You may use gitignore for advanced gitignore file generation. It's fast, easy and cutting edge tags are automatically generated for you.

Use this link for most of jetbrains softwares (intelij, phpstorm...) jetbrains .gitignore file

[edit]

Below is the generated gitignore file for Jetbrains Softwares, this will prevent you from sharing sensitive informations (passwords, keystores, db passwords...) used by any of Jetbrains software to manage projects.

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

### Intellij ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm

*.iml

## Directory-based project format:
.idea/
# if you remove the above rule, at least ignore the following:

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

# Sensitive or high-churn files:
# .idea/dataSources.ids
# .idea/dataSources.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:
*.ipr
*.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

Generated code is also well commented. hope it helps :)

Williem
  • 1,131
  • 1
  • 12
  • 19
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. – Himanshu Apr 01 '15 at 04:02
  • @Himanshu The link is to a search engine of gitignore files. What do you suggest should be copied from it into the post? – Dan D. Apr 01 '15 at 09:30
4

For me there was only one solution to remove .idea folder than commit file .gitignore with ".idea" and than use IDE again

4

I suggest reading the git man page to fully understand how ignore work, and in the future you'll thank me ;)

Relevant to your problem:

Two consecutive asterisks ("**") in patterns matched against full pathname may have special meaning:

A leading "**" followed by a slash means match in all directories. For example, "**/foo" matches file or directory "foo" anywhere, the same     as pattern "foo". "**/foo/bar" matches file or directory "bar" anywhere that is directly under directory "foo".

A trailing "/**" matches everything inside. For example, "abc/**" matches all files inside directory "abc", relative to the location of the .    gitignore file, with infinite depth.

A slash followed by two consecutive asterisks then a slash matches zero or more directories. For example, "a/**/b" matches "a/b", "a/x/b",     "a/x/y/b" and so on.

Other consecutive asterisks are considered invalid.
Steve Benner
  • 1,679
  • 22
  • 26
4

I tried to added those files into my .gitignore and it was useless...

Nevertheless, as Petr Syrov said, you can use git rm -r --cached .idea into your terminal and those files won't be a problem anymore!

frisinacho
  • 160
  • 1
  • 1
  • 11
4

What about .idea/* ? Didn't test, but it should do it

ksol
  • 11,835
  • 5
  • 37
  • 64
3

JetBrains has a .gitignore_global on GitHub.

Jeff Wolski
  • 6,332
  • 6
  • 37
  • 69
2

For all JetBrains IDEs:

Settings > Editor > File Types > Ignored Files and Folders, press + sign and add .idea to ignored list.

Alternatively, add to .gitignore (for committing) or .git/info/exclude (for local) the line .idea/.

qwr
  • 9,525
  • 5
  • 58
  • 102
1

Use .ignore plugin: https://plugins.jetbrains.com/plugin/7495--ignore

It manages a lot of paths/patterns for you automatically and also has many useful extra features. It's compatible with:

  • IntelliJ IDEA
  • PhpStorm
  • WebStorm
  • PyCharm
  • RubyMine
  • AppCode
  • CLion
  • GoLand
  • DataGrip
  • Rider
  • MPS
  • Android Studio
Mir-Ismaili
  • 13,974
  • 8
  • 82
  • 100
0

If you've already made an initial commit and you have .idea files showing up as new files in git, you will need to remove the files first and then commit them. The following steps will do the trick

 1. git rm --cached -r .idea/
 2. Add .idea/ to **.git/info/exclude** or **.gitignore**
 3. git commit -m 'ignore .idea/ files'

It's explained in detail in this link here: https://devconnected.com/how-to-clear-git-cache/

benitta.ruphus
  • 106
  • 1
  • 6
0

.gitignore, which is a file used to explicitly specify which files or folders should be ignored by Git

The ignore rules specified in $HOME/.gitignore_global, $HOME/.config/git/ignore, $GIT_DIR/info/exclude, .gitignore are all in effect in the Git repository

A .gitignore file explicitly specifies which files should not be tracked by Git, i.e., ignored by Git. Files that were already tracked by Git before being gitignore are not affected by the gitignore rule.. To stop tracking a file that is already tracked by Git, use the git rm --cached .idea/ command

marie
  • 180
  • 1
  • 8