How do I ignore PyCharm configuration files in a git repository?

PythonGitPycharm

Python Problem Overview


I don't want to commit my PyCharm config files (e.g. .idea/codeStyleSettings.xml) to my git repository, so I added the following to my .gitignore file:

.idea/
mydjangosite/.idea/

However, every time I try to make a commit within PyCharm (command k), it still wants to commit these files. How do I get PyCharm to recognize my .gitignore file and not commit these files?

Python Solutions


Solution 1 - Python

If PyCharm offers you to commit the files, it means that you have already added them to Git. You need to remove them using 'git rm --cached' and commit the change. After that, they will be ignored by the integration according to your .gitignore settings.

Solution 2 - Python

You can configure ignored files.

> Under the Version Control node, of the Settings dialog box, click Ignored Files. The Ignored Files dialog box opens.

More easily:

> Tip > >You can also add files to ignore list on-the-fly. A new file under the Unversioned Files change list, has Ignore command on its context menu.

Solution 3 - Python

  • Remove the .idea folder (keep a copy)
  • Commit the changes

Add the following to the gitignore

(JetBrains recommended exclusions for PyCharm that also covers JetBrains plugins etc):

### 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
  • Now you can add your .idea folder back into your project directory and the changes won't be tracked any more.

Solution 4 - Python

You should not ignore all of the files under .idea directory. Some of them are local and tied to your personal preferences and some other are global settings of the PyCharm project that most likely should be stored in git.

Here is the link to an updated .gitignore snippet for PyCharm and other JetBrains IDEs.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJamie ForrestView Question on Stackoverflow
Solution 1 - PythonyoleView Answer on Stackoverflow
Solution 2 - PythonGareth LattyView Answer on Stackoverflow
Solution 3 - PythonChris HalcrowView Answer on Stackoverflow
Solution 4 - PythonsophrosView Answer on Stackoverflow