Search code examples
ideeditorphpstorm

PhpStorm automatically ignore files from .gitignore


I'm new to PhpStorm, and I'm trying to get it to automatically ignore files specified in my .gitignore file when adding a file tree to git. I know you can add ignore rules to PhpStorm itself, but I want it to use the rules from my .gitignore file.

Basically I already have a .gitignore file with ignore rules, I just want PhpStorm to follow those rules when adding files (git add) so that none of the files matching the .gitignore rules will be accidentally added to a commit.


Solution

  • I know in the past this has happened to me as well, so it seems a bit fragile. I never do a git add for the entire directory since it has done things like add files in the /vendor directory (which is always in the gitignore file).

    But having said that, I was curious, so I did a test as I think it might be related to when things happen (like when git is engaged, or when the .gitignore is added).

    I did the following steps on a new project and it worked appropriately, so maybe that will help, you can give it a try and see if it works for you as well. I am working with 2016.1.2

    • Create the project
    • Select VCS...Enable Version Control Integration and select Git
    • Create the .gitignore in the root directory
    • In the project, create a new directory called ignore
    • In the .gitignore, add ignore/ and the ignore directory should turn light gray
    • Create a.txt in the root directory
    • create b.txt in the /ignore directory
    • right click on whole project and select git add and b.txt under the ignore directory is not added, but a.txt is