Search code examples
gitcmdescapingwindows-shellmsysgit

git grep for less than or greater than character (in Windows shell)


I'm trying to grep the word <template> in a git repository.

How do I write my git grep statement for this? (Shell seems to assume < and > as redirection parameters)

(Looks like this is specific to git for windows run from a cmd session. Git Bash works fine)


Solution

  • Using Git Bash, you should be able to simply quote it: git grep "<template>"....

    Running Git via Windows' cmd.exe is a little bit different. There, git grep ^<template^> ... should work. This is because cmd.exe uses ^ as its escape character (rather than \, which is used in Bash, ZSH, and just about every other shell out there).

    See also this question.