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:
- Why is .idea/.gitignore generated (even though there is already a .gitignore in project root)?
- Does .idea/.gitignore need to be committed to the repository or should it be ignored?
Please sign in to leave a comment.
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)
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
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
Another example is that I could not find anything about this *internal* .idea/.gitignore file in IntelliJ documentation
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/)
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
.