Skip to content

Excluding files in git grep

I often use git grep to search around my files because I’m more used to it than other searching tools (such as regular grep) and it’s recently become more common for me to want to exclude a pattern from my search.

$ git grep FindThisThing ":(exclude)*_test.go"

The git grep command accepts a <pathspec> as an argument, and in order to exclude a pattern. Above, exclude is the “magic word” in the pathspec to say “ignore test files”.

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.