Git grep


Git grep is a useful command to search contents within a Git repository:

git grep <pattern>

Examples

To see the files and lines where text is foo:

git grep foo

To see line numbers:

git grep -n foo

To see only the files:

git grep -l foo

To search within commit reference(s):

git grep foo my_branch
git grep foo HEAD~3
git grep foo abc1234 def5678

To search with regex:

git grep -e "^foo"
git grep -e foo --or bar
git grep -e "^foo" --and -e "bar$"


Please support this site and join our Discord!