Why is IntelliJ creating a .gitignore file in .idea folder even though I have .gitignore file in my project root and should it be ignored or committed to repository??

Answered

I use IntelliJ Ultimate 2023.1

I have a project and in the project root, I have my .gitignore file.

However, once I opened that project in intelliJ, I see that beside my .gitignore file in the project root, there is another one .idea/.gitignore file in .idea folder:

  1. Why is .idea/.gitignore generated (even though there is already a .gitignore in project root)?
  2. Does .idea/.gitignore need to be committed to the repository or should it be ignored?
0
4 comments

Greetings, 

Idea/gitignore file is an internal IDE file used to ignore certain IDEA-related folders. 

Generally, the best practice is to also have your own gitingnore file located in the root of the project. 

As for the repository question, please see: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839-How-to-manage-projects-under-Version-Control-Systems

So yes, .gitignore placed in the IDEA folder also needs to be in the repo. (recommended)

1

Thank you Dino Letic but I find the link you shared and IntelliJ documentation about this very unclear, incomplete, conflicting, inaccurate, difficult to find.

As an example, the link you shared (https://intellij-support.jetbrains.com/hc/en-us/articles/206544839-How-to-manage-projects-under-Version-Control-Systems) states that everything under .idea folder should be shared except these 3 files

  • workspace.xml
  • usage.statistics.xml
  • shelf directory

Yet, going to gitignore.io (https://www.toptal.com/developers/gitignore/api/intellij) and generating .gitignore file by selecting IntelliJ shows many more files that need to be ignored.  Here is what gets generated

# Created by https://www.toptal.com/developers/gitignore/api/intellij
# Edit at https://www.toptal.com/developers/gitignore?templates=intellij

### Intellij ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
# 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

# AWS User-specific
.idea/**/aws.xml

# 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/artifacts
# .idea/compiler.xml
# .idea/jarRepositories.xml
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# *.iml
# *.ipr

# 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

# SonarLint plugin
.idea/sonarlint/

# 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

### Intellij Patch ###
# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721

# *.iml
# modules.xml
# .idea/misc.xml
# *.ipr

# Sonarlint plugin
# https://plugins.jetbrains.com/plugin/7973-sonarlint
.idea/**/sonarlint/

# SonarQube Plugin
# https://plugins.jetbrains.com/plugin/7238-sonarqube-community-plugin
.idea/**/sonarIssues.xml

# Markdown Navigator plugin
# https://plugins.jetbrains.com/plugin/7896-markdown-navigator-enhanced
.idea/**/markdown-navigator.xml
.idea/**/markdown-navigator-enh.xml
.idea/**/markdown-navigator/

# Cache file creation bug
# See https://youtrack.jetbrains.com/issue/JBR-2257
.idea/$CACHE_FILE$

# CodeStream plugin
# https://plugins.jetbrains.com/plugin/12206-codestream
.idea/codestream.xml

# Azure Toolkit for IntelliJ plugin
# https://plugins.jetbrains.com/plugin/8053-azure-toolkit-for-intellij
.idea/**/azureSettings.xml

# End of https://www.toptal.com/developers/gitignore/api/intellij

Another example is that I could not find anything about this *internal* .idea/.gitignore file in IntelliJ documentation

0

IntelliJ IDEA creates a .gitignore file in the .idea folder to manage project-specific settings. This file is generated automatically and should not be committed to the repository. The .gitignore file in the project root should be used for versioning and shared among team members. Ensure that the .idea folder, including its .gitignore file, is listed in your global .gitignore or the project's root .gitignore to avoid unintentional commits.
To make it more easy, check out detailed article with coding (https://techkluster.com/git/questions-git/reset-local-branch-remote-repository/)

-1

The file .idea/.gitignore is maintained by the JetBrains team. It contains files from the .idea directory that are not supposed to be in Git. This file refers only to the .idea directory. If in the future when you create or it is created a new file in the .idea directory that is not supposed to be in Git, Idea itself will edit the .idea/.gitignore file. Therefore, it is a separate file to avoid conflicts with your project's .gitignore file. So you don't care about the .idea directory in your project .gitignore file, you leave that to IntelliJ idea and its .gitignore. The .idea/.gitignore file belongs to Git, of course, just like your project .gitignore.

0

Please sign in to leave a comment.