What is git grep, and how does it differ from a normal file search?

Last updated 6 July 2026

git grep searches the content of files tracked by Git, using Git's index and object database rather than scanning the filesystem. It's faster and more precise than a generic search because it knows exactly which files are versioned and can search any commit or tree, not just the working tree.

  • Searches tracked content only: Ignores untracked files, build artifacts, and anything in .gitignore, so no noise from node_modules or .git.

  • Can search history, not just the disk:

    • git grep "foo" <commit> searches any commit or tree by reading objects directly.

    • A tool like grep -r can only see the current working directory.

  • Fast and Git-aware: Uses the index and multiple threads, so it's typically quicker than recursive filesystem grep on a repo.

  • Handy options: -n show line numbers, -i case-insensitive, -l list only filenames, -e for patterns and --and/--or to combine them.

  • https://git-scm.com/docs/git-grep/2.18.0
  • https://git-scm.com/docs/git-grep
  • https://www.kernel.org/pub/software/scm/git/docs/git-grep.html
  • https://git-scm.com/book/cs/v2/Git-Tools-Searching
  • https://git-scm.com/book/en/v2/Git-Tools-Searching
  • https://git-scm.com/book/de/v2/Git-Tools-Suchen
  • https://www.geeksforgeeks.org/git/git-grep/
  • https://medium.com/@ahmedmuhumed/git-grep-command-c6682da0dbb3
All Git interview questions