How to ignore files with PhpStorm and Git?

For the first question, as you found in the link.

For the second question, if you want to ignore a file which has already version controlled by git, you should use git command to do that:

  1. In the local repo, add the file name in .gitignore file. If you don’t have .gitignore, you can use touch .gitignore.
  2. git rm --cached filename.

After reading your comments I think what you really need here is lock file feature, that exists (as far as I know) only on gitlab. But... this requires central server so it's actually against git main idea.

In most cases - as Stony said - you should create template file like config.template.php or config.dev.php, add config.php to .gitignore and make each developer rename/recreate config.php.

Another way would be to create deploy script with transformation instructions that'll automatically adjust paths inside config file, maybe automatically deploy entire application, and run it at each deploy.

Or simply exclude config file every time you commit changes.


It make no sense to ignore files that are already in your version control. So you have to remove them first with:

git rm --cached filename

then that files exist locally but are removed from your repository. Then you can ignore that files.