I do this often after shelling out to bash

$ git grep 'banner-image' | grep mb3

Can I do it without leaving emacs?

  • 1
    M-x grep followed by the input grep -nH -e banner-image | grep mb3 RET. (The grep -nH -e is provided by default.) As usual for M-x grep, this gives you a grep output buffer with the search hits. See (emacs) Grep Searching.
    – Drew
    Sep 3, 2017 at 5:40
  • Is your solution "recursive", because git grep is recursive by default Sep 3, 2017 at 5:41
  • Use rgrep if you want recursive`.
    – Drew
    Sep 3, 2017 at 5:42
  • the .git folder contains two thousand files not for human consumption. git grep by default ignores that folder. does your solution take that in to account. Sep 3, 2017 at 5:44
  • Try grep-find-template.
    – Drew
    Sep 3, 2017 at 14:36

1 Answer 1


I have counsel (and ivy and swiper and ivy-hydra) loaded, and have "ctrl-c j" bound to counsel-git-grep, which works well for the LHS of your pipeline. It is not clear if the RHS of your pipeline is trying to match more of the line or the filename. If the former then I would tend to add a space and mb3, if the latter then I would use "ctrl-c ctrl-o" ivy-occur to save the git grep output in a buffer, and then use "ctrl-s" to search this new buffer for mb3, pressing enter to visit the place.

All of these packages are available from melpa.org.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.