Search code examples
gitgitignore

How can I ignore all files except those with a certain extension in git?


I need to ignore all files except those ending in .php, .css, .html or .js.

This is what I have in my .gitignore file for now:

*
!.php
!/*.php
!*.php

It does ignore everything, but only permits .php files in root directory, while hiding all the rest.


Solution

  • *
    !*/
    !*.php
    !*.css
    !*.html
    !*.js