Skip to content

Instantly share code, notes, and snippets.

@benjamincharity
Created February 26, 2016 16:19
Show Gist options
  • Save benjamincharity/94604beb49e6258483d0 to your computer and use it in GitHub Desktop.
Save benjamincharity/94604beb49e6258483d0 to your computer and use it in GitHub Desktop.
Git grep within a specific sub-directory.
# Search for `analytics` only inside `./src/app`
git grep analytics -- "./src/app/*"
@nickmeldrum
Copy link

on my version of git (2.17.1) the following behaves the same as above with less characters to type:

git grep analytics src/app

@iafsilva
Copy link

iafsilva commented Mar 27, 2019

@nickmeldrum what if you want to search for 'src/app'? how would you do that?

Sometimes it's not so much about 'less characters' but more about the precision of the command.
The double dash is an delimiter for 'end of options' so the program is sure that you're sending paths instead of search arguments.
It can be applied to most coreutils and you can find more on this answer

@benjamincharity Exactly what I was looking for. thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment