git grep
Searches tracked files in the repository for a pattern. Faster than regular grep for Git repositories.
Syntax
git grep [<options>] <pattern> [<rev>] [-- <path>...]
Options
- -n / --line-number: Shows line numbers
- -c / --count: Shows only the count of matching lines per file
- -i / --ignore-case: Ignores case when matching
- -l / --files-with-matches: Shows only filenames containing the pattern
- -w / --word-regexp: Matches the pattern only at word boundaries
- -e <pattern>: Specifies the pattern (useful with multiple patterns)
- --and / --or / --not: Combines multiple patterns with boolean logic
Example
git grep "TODO" git grep -n "fixme" -- "*.ts" git grep --count "console.log"