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

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


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


For those, who would like to include file extensions which are located in subdirs like @jmborr and @Racso

# .gitignore for excluding all but certain files in certain subdirs*!*.cfg!/**/!certain/subdir/i_want_to_include/*.cfg

when you exclude everything ('*'), you have to white-list folders ('/**/'), before being able to white-list files.

Found in: https://stackoverflow.com/a/33983585/5388625