Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Allow only some files in subdirectories with .gitignore

Tags:

gitignore

I have dir structure like this:

static     admin     ajax_upload     books     css     font     media     robots.txt templates src build lib 

I want to ignore following direcotories:

  • lib
  • build
  • src
  • static

I want to allow following:

  • static/css/bootstrap-styled.css
  • static/css/main.css
  • static/css/font-*.css
  • static/font
  • static/media/default.png
  • static/robots.txt
  • templates

So I use the following .gitignore:

# Ignore /lib /src /build /static/*  # Allow !/static/css/bootstrap-styled.css !/static/css/main.css !/static/css/font-*.css !/static/font !/static/media/default.png !/static/robots.txt 

But it doesn't work properly. Could you help me - what I do wrong here? TIA!

Details

Real project structure is like this:

static     admin         css         img         js             admin     ajax_upload     books     css     font     media         uploads             blog             gallery         default.png     robots.txt templates src build lib 
like image 959
Dmitry Belaventsev Avatar asked May 01 '13 05:05

Dmitry Belaventsev


People also ask

Does .gitignore work in subdirectories?

gitignore file is usually placed in the repository's root directory. However, you can create multiple . gitignore files in different subdirectories in your repository.

Does Gitignore ignore subdirectories?

gitignore file does not exclude the directories unless I fully qualify the ignore pattern as Solution/Project/bin/Debug - which I don't want to do as I will need to include this full pattern for each project in my solution, as well as add it for any new projects added. Any suggestions?

How do I not ignore a specific file in git?

Git ignore patterns An asterisk is a wildcard that matches zero or more characters. Prepending an exclamation mark to a pattern negates it. If a file matches a pattern, but also matches a negating pattern defined later in the file, it will not be ignored.


1 Answers

So, the .gitignore works for me is the following:

# Ignore lib/ src/ build/ static/**/*  # Allow !static/css/bootstrap-styled.css !static/css/main.css !static/css/font-*.css !static/font/* !static/media/default.png !static/robots.txt 
like image 63
Dmitry Belaventsev Avatar answered Sep 20 '22 04:09

Dmitry Belaventsev