Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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.

like image 783
user Avatar asked Jan 29 '12 00:01

user


People also ask

How do I exclude files from a Git repository?

Open the . git/info/exclude file in a text editor and add the folder to ignore. This file remains private to you.

Can you have multiple Git ignore files?

A . gitignore file is a plain text file where each line contains a pattern for files/directories to ignore. Generally, this is placed in the root folder of the repository, and that's what I recommend. However, you can put it in any folder in the repository and you can also have multiple .

What is the extension of a Gitignore file?

A file with the GITIGNORE file extension is a Git Ignore file used with the version/source control system called Git.


2 Answers

* !*/ !*.php !*.css !*.html !*.js 
like image 140
Fivell Avatar answered Sep 22 '22 00:09

Fivell


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

like image 22
quin Avatar answered Sep 25 '22 00:09

quin