27

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.

corazza
  • 31,222
  • 37
  • 115
  • 186
user
  • 2,939
  • 5
  • 26
  • 39

2 Answers2

41
*
!*/
!*.php
!*.css
!*.html
!*.js
Fivell
  • 11,829
  • 3
  • 61
  • 99
2

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

quin
  • 21
  • 3