'git grep' and word boundaries on Mac OS X and BSD

I run git grep "\<blah\>" regularly on my linux development server, but I just discovered that I am not able to use \< and \> on Mac (Mac OS X 10.6.8) (not able to use = it does not find anything). Is the regular expressions syntax different in Mac?

I tried using git grep -E "\<blah\>" but to no avail! 🙁

  • SVN / Git / Bash
  • Git workflow/Deployment
  • Combining SVN and Git
  • GIT workflow w/ multiple workstations and a centralize server
  • Using the execute shell command in Jenkins to run git commands on a Windows machine
  • Pull in changes from a Github fork
  • 3 Solutions collect form web for “'git grep' and word boundaries on Mac OS X and BSD”

    I guess it’s caused by the BSD vs Linux grep library.

    See if the -w (match pattern only at word boundary) option to git grep does it for you:

    $ git grep -w blah

    You can compile git with PCRE support and use git grep -P "\bblah\b" for word boundaries.

    Here’s a guide on how to compile git using OSX Homebrew:

    After struggling with this, too, I found this very helpful post on a BSD mailing list. So here’s the (albeit rather ugly) solution:

    git grep "[[:<:]]blah[[:>:]]"

    The -w flag of git-grep also works but sometimes you want to only match the beginning or end of a word.

    Update: This has changed in OS X 10.9 “Mavericks”. Now you can use \<, \>, and \b. [[:<:]] and [[:>:]] are no longer supported.

    Git Baby is a git and github fan, let's start git clone.