Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make git ignore a sub directory group with gitignore pattern?

Tags:

git

I've a directory projects/ in root directory. the root directory is added to git. in projects I've several subdirectories. But I want to track only projects/admin not projects/x nor projects/y. What ignore rule I need to write in .gitignore ?

like image 373
Neel Basu Avatar asked Aug 26 '11 19:08

Neel Basu


2 Answers

You can use a negative ignore clauses, e.g.:

project/*
!project/admin
!project/admin/*
like image 153
Nicolas Buduroi Avatar answered Oct 02 '22 22:10

Nicolas Buduroi


projects/*
!projects/admin

The ! prefix before a line negates it; i.e. the directory or file given in that line will not be ignored.

like image 43
Tamás Avatar answered Oct 02 '22 22:10

Tamás