Git grep – The best grep there is!

If you find yourself ‘greping’ your git repositories often, git provide a very handy tool/option that can speed things up. The git grep option allows you to grep any git repository, with one simple advantage – it’s a lot faster.

Searching is as simple as running the following command from your git repository:

The unix grep equivalent of this would be:

Notice two things are different here:

  • No -r flag – While doing a git grep, git searches your current folder and down, so you could say the search is recursive by default.
  • No path required – Again, since git grep automatically searches your current folder and down, this is kind of redundant. But if you want to specify the path exclusively, you can using the “- -” option (covered later).

Git grep retains many flags of unix grep such as -n for lineNumber, -i for case insensitive search … etc

To search in files by name or extension, unix grep has the – -include option, the same with git becomes

The above command would search for “foo” in a case insensitive manner in files ending with py.


Howdy! You're reading my blog. To know more about me click here

One thought on “Git grep – The best grep there is!

Leave a Reply

Your email address will not be published. Required fields are marked *