user
user

Reputation: 3199

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.

Upvotes: 28

Views: 12038

Answers (2)

quin
quin

Reputation: 23

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

Upvotes: 2

Fivell
Fivell

Reputation: 11929

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

Upvotes: 41

Related Questions