Ripgrep (rg) is a better grep. I would advice you to switch to it.

A short one, but this was not immediately obvious to me when searching through the Ripgrep man page. When performing a search, you can use the -g flag to ignore a folder. Now do not get me wrong, it is mentioned in the man page. I was however searching through the man page for “ignore”, while I should have been searching for “exclude”. Here is the relevant excerpt.

-g, --glob GLOB ...

Include or exclude files and directories for searching that match the given glob. This always overrides any other ignore logic. Multiple glob flags may be used. Globbing rules match .gitignore globs. Precede a glob with a ! to exclude it.

Thus, if you want to search for foo occurrences, but are not interested in anything in the bar folder, you can use

rg foo -g '!bar/'

Note that without the /, a file called bar will also be ignored.