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

412    Asked by Amitraj in Tableau , Asked on Jul 1, 2021

 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). How git ignore everything except?

To ignore the root file and root directories you could use:

/*

/*/

!/bin/

The above commands will ignore the root directories and root files, then un-ignores the root bin directory. Thus, you will get all of the bin directory, which includes subdirectories and their files.

This is the way git can ignore everything except subdirectories.



Your Answer

Interviews

Parent Categories