Git Ignoring Files and Folders Exceptions in a .gitignore file

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Example

If you ignore files by using a pattern but have exceptions, prefix an exclamation mark(!) to the exception. For example:

*.txt
!important.txt

The above example instructs Git to ignore all files with the .txt extension except for files named important.txt.

If the file is in an ignored folder, you can NOT re-include it so easily:

folder/
!folder/*.txt

In this example all .txt files in the folder would remain ignored.

The right way is re-include the folder itself on a separate line, then ignore all files in folder by *, finally re-include the *.txt in folder, as the following:

!folder/
folder/*
!folder/*.txt

Note: For file names beginning with an exclamation mark, add two exclamation marks or escape with the \ character:

!!includethis
\!excludethis


Got any Git Question?