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
  • 30,052
  • 35
  • 108
  • 182
user
  • 2,479
  • 3
  • 25
  • 39

2 Answers2

40
*
!*/
!*.php
!*.css
!*.html
!*.js
Fivell
  • 11,514
  • 3
  • 58
  • 95
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