info > GIT-GREP(1)

๐Ÿ“› NAME

git-grep โ€“ Print lines matching a pattern

๐Ÿš€ Quick Reference

Use CaseCommandDescription
๐Ÿ” Search tracked files for a patterngit grep <pattern>Search working tree tracked files
๐Ÿ”ค Caseโ€‘insensitive searchgit grep -i <pattern>Ignore case when matching
๐Ÿ—‚๏ธ Search only file namesgit grep -l <pattern>List files that contain matches
๐Ÿšซ Invert matchgit grep -v <pattern>Show lines that do NOT match
๐Ÿ”ข Show line numbersgit grep -n <pattern>Prefix line numbers to output
๐Ÿงฎ Count matches per filegit grep -c <pattern>Show count of matching lines
๐Ÿ“„ Search staged (cached) contentgit grep --cached <pattern>Search blobs in the index
๐Ÿ“œ Search specific tree (commit/tag)git grep <pattern> <tree>Search blobs in given tree objects
๐Ÿ“ Limit to file patternsgit grep <pattern> -- '*.c'Restrict search to matching paths
๐Ÿ”ฌ Boolean combinationsgit grep -e 'pattern1' --and -e 'pattern2'Combine patterns with AND/OR/NOT

๐Ÿ“– SYNOPSIS

git grep [-a | --text] [-I] [--textconv] [-i | --ignore-case] [-w | --word-regexp]
          [-v | --invert-match] [-h|-H] [--full-name]
          [-E | --extended-regexp] [-G | --basic-regexp]
          [-P | --perl-regexp]
          [-F | --fixed-strings] [-n | --line-number] [--column]
          [-l | --files-with-matches] [-L | --files-without-match]
          [(-O | --open-files-in-pager) [<pager>]]
          [-z | --null]
          [ -o | --only-matching ] [-c | --count] [--all-match] [-q | --quiet]
          [--max-depth <depth>] [--[no-]recursive]
          [--color[=<when>] | --no-color]
          [--break] [--heading] [-p | --show-function]
          [-A <post-context>] [-B <pre-context>] [-C <context>]
          [-W | --function-context]
          [--threads <num>]
          [-f <file>] [-e] <pattern>
          [--and|--or|--not|(|)|-e <pattern>...]
          [--recurse-submodules] [--parent-basename <basename>]
          [ [--[no-]exclude-standard] [--cached | --no-index | --untracked] | <tree>...]
          [--] [<pathspec>...]

๐Ÿ“ DESCRIPTION

Look for specified patterns in the tracked files in the work tree, blobs registered in the index file, or blobs in given tree objects. Patterns are lists of one or more search expressions separated by newline characters. An empty string as search expression matches all lines.

โš™๏ธ OPTIONS

๐Ÿ’ก EXAMPLES

git grep 'time_t' -- '*.[ch]'

 ๐Ÿ” Looks for time_t in all tracked .c and .h files in the working directory and its subdirectories.

git grep -e '#define' --and \( -e MAX_PATH -e PATH_MAX \)

 ๐Ÿ” Looks for a line that has #define and either MAX_PATH or PATH_MAX.

git grep --all-match -e NODE -e Unexpected

 ๐Ÿ” Looks for a line that has NODE or Unexpected in files that have lines that match both.

git grep solution -- :^Documentation

 ๐Ÿ” Looks for solution, excluding files in Documentation.

๐Ÿงต NOTES ON THREADS

The --threads option (and grep.threads configuration) will be ignored when --open-files-in-pager is used, forcing singleโ€‘threaded execution.

When grepping the object store (with --cached or giving tree objects), running with multiple threads might perform slower than single threaded if --textconv is given and there are many text conversions. So if you experience low performance in this case, it might be desirable to use --threads=1.

๐Ÿ”ง CONFIGURATION

๐Ÿ“š GIT

Part of the git(1) suite. Git 2.34.1 02/26/2026

GIT-GREP(1)
๐Ÿ“› NAME ๐Ÿš€ Quick Reference ๐Ÿ“– SYNOPSIS ๐Ÿ“ DESCRIPTION โš™๏ธ OPTIONS ๐Ÿ’ก EXAMPLES ๐Ÿงต NOTES ON THREADS ๐Ÿ”ง CONFIGURATION ๐Ÿ“š GIT

Generated by phpman v4.9.25-25-g40dbf62 · Markdown · JSON · MCP Author: Che Dong Under GNU General Public License
2026-07-14 07:15 @216.73.217.135
CrawledBy Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)
Valid XHTML 1.0 Transitional!Valid CSS!
Enhanced by LLM: deepseek-v4-pro / taotoken.net / www.chedong.com - original format

^_top_^