How do you get git grep
to return results without a pager? Grep does this by default. When I pipe git grep
to cat: git grep foo | cat
it does this but it loses the highlighting on the match. I want to keep the highlighting on the match without doing git grep foo | cat | grep foo
.
Asked
Active
Viewed 3,782 times
18

eatonphil
- 13,115
- 27
- 76
- 133
-
1You could configure the pager.grep options like this: ``` git config --global pager.grep false ``` – mxi1 Mar 01 '21 at 08:49
1 Answers
26
You can either use the --no-pager
parameter like git --no-pager grep foo
or tell grep to always do the highlighting even if you pipe the result to some other process with git grep --color=always foo | cat
. Or you can set the config option core.pager
to cat
like git -c core.pager=cat grep foo
or of course permanently with git config core.pager cat
which will then work for all Git commands that would be sent to the pager and also preserves the highlighting.

Vampire
- 35,631
- 4
- 76
- 102