Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I occasionally need to grep through git submodules for which I use:

git submodule foreach 'git grep x'

However, since switching to zsh I find a less prompt is opened for each submodule, even when there are no options. What I'd much prefer is for all of the output to be printed out to the terminal.

My current solution is to call:

git submodule foreach 'git grep x' > /tmp/a && cat /tmp/a

Which achieves what I want but I can't help but feel that I'm missing an option or a more elegant solution. Is there one?

share|improve this question
Related on SO: How do I prevent git diff from using a pager? – depquid Apr 24 '13 at 12:39
up vote 3 down vote accepted

Try changing the pager that git uses:

GIT_PAGER="cat" git submodule foreach 'git grep x'

Or if you want less to be used, but only when output will run off of the screen:

GIT_PAGER="less -FX" git submodule foreach 'git grep x'

You can set the pager per project by using git config, or you can, of course, set the environment variables globally.

share|improve this answer
Perfect - went for the latter, exactly what I wanted, thanks! – Andy Smith Apr 24 '13 at 12:51

Just to cover the other methods:

Method #1: --nopager

git submodule foreach 'git --nopager grep x'

Method #2: completely disable pager

git config --global core.pager cat

From the git-config man page:

core.pager The command that git will use to paginate output. Can be overridden with the GIT_PAGER environment variable. Note that git sets the LESS environment variable to FRSX if it is unset when it runs the pager. One can change these settings by setting the LESS variable to some other value. Alternately, these settings can be overridden on a project or global basis by setting the core.pager option. Setting core.pager has no effect on the LESS environment variable behaviour above, so if you want to override git’s default settings this way, you need to be explicit. For example, to disable the S option in a backward compatible manner, set core.pager to less -+S. This will be passed to the shell by git, which will translate the final command to LESS=FRSX less -+S.

Method #3: pager.<cmd>

You can also disable paging for single git subcommands by using pager. setting instead of core.pager and you can change your settings per git repository (omit --global).

git config --global pager.grep cat

From the git-config man page:

pager. If the value is boolean, turns on or off pagination of the output of a particular git subcommand when writing to a tty. Otherwise, turns on pagination for the subcommand using the pager specified by the value of pager.. If --paginate or --no-pager is specified on the command line, it takes precedence over this option. To disable pagination for all commands, set core.pager or GIT_PAGER to cat.

Method #4: Modifying less' behavior (-F -X)

You can reconfigure less so that it "conditionally" pages only for files whose content is larger than a screens worth (-F), and disable less from clearing the screen afterwards (X).

git config --global core.pager less -F -X


share|improve this answer

In this case I used to re-page the whole command

git submodule ... | less

but we lose any potential formatting from sub-commands.

Then I realized we have the same issue with "git status", so after reading the answer to "How can I turn on a pager for the output of git status?" I would suggest

git config --global pager.submodule "less -FX"
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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