git grep

Mar 11, 2019 · Follow on Twitter and Mastodon
git

This is a short note to my future self on how to use git grep instead of grep to find all occurrences of a certain text in all files within a git repository folder.

I used to use grep to achieve this, but always had to lookup the syntax. Also, it’s not as quick and intuitive as I’d like it to be. git grep is a LOT faster, and much easier to use.

To use git grep instead of grep, you just have to type:

git grep 'the string to search for'

To narrow it down to only search in certain types of files, just add a file pattern:

git grep 'the string to search for' *.txt

This is a lot easier to use, and MUCH faster than grep.