Search code examples
gitgitignore

Keeping multiple .gitignore files (local and remote) in the same repository


I have a repository with a .gitignore file, which excludes build paths (eg. vendor/ from Composer).

I also have some local IDE paths (eg. .idea from PhpStorm) that I want to ignore, but that aren't in the repository's .gitignore file.

I'm not sure how to do this. If git looked for files like .gitignore_* in the folder, then I could just add a .gitignore_local that contains (among other things) its own name.


Solution

  • For local ignores, you can add them to the .git/info/exclude file. This is not shared to remote repositories.

    So add to .gitignore all the files that should be ignored by anyone working with the repository. Add to .git/info/exclude files you use personnally but other people have no reason to have them, therefore to ignore them.