Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in DevOps and Agile by (29.3k points)

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).

1 Answer

0 votes
by (50.2k points)

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 to tell git to ignore everything except subdirectories.

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...