205

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
1
  • 10
    perhaps you already comitted; you need to git rm; add it to ignore. Commented Oct 23, 2013 at 6:45

20 Answers 20

343

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

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks alot! But why its in the cache after i checkout a totaly empty repository?
Thank you, extremely useful. Used this to remove the files then added .idea to the gitignore and it worked great. Thank you so much!
That doesn't really work when the .idea folder is already under tracking
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.
288

just .idea/ works fine for me

9 Comments

hi there! wanna tell us more how u do it...ain't working for me? :(
@BradBird I just tried it - works for subfolders as well. Also you may want to give a try to **/.idea/
Part of the issue is if you've already staged your stuff, the .gitignore will not help.
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: help.github.com/articles/ignoring-files
@DanRosenstark thank you! this was what was wrong in my case... everyone should check this before looking at their .gitignore file
|
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).

4 Comments

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.
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.
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.
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.
30

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

1 Comment

This should be the more comprehensive answer!
29

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

Comments

25

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.

Comments

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

Comments

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

Comments

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

Comments

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.

Comments

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 :)

2 Comments

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 The link is to a search engine of gitignore files. What do you suggest should be copied from it into the post?
4

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

Comments

4

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

1 Comment

hi there! I tried this! but the IDE couldn't reload my files again... how did u do this? thanks!
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.

Comments

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!

Comments

3

JetBrains has a .gitignore_global on GitHub.

Comments

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/.

Comments

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

Comments

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/

Comments

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.