Alex Rivera | Logout

How do I tell Git to ignore everything except a subdirectory?

Asked 2009-08-08T11:04:39.857
289

I want to ignore all files in my repository except those that occur in the bin subdirectory. I tried adding the following to my .gitignore:

*
!bin/*

This does not have the desired effect, however: I created a new file inside of bin/, but doing git status still shows nothing to commit (working directory clean).

Any suggestions?

Edit
Report

1 Answer

12

I think a better way would be to anchor each pattern to the top git directory by starting the pattern with a slash:

/*
!/public_html
!/.gitignore

Instead of ignoring all files it will only ignore top level files, not the ones in the directory you dont want to ignore.

answered 2010-11-05T21:18:13.313

Your Answer