0

I'm a little confused with the following behavior of git commands in the Windows Command prompt.

This shows a result comparable to VIM (I think) with interactive list

git branch -a

Result is something like the following and I've no idea what key-combinations to use to scroll through the output (I did notice that q ends the output).

enter image description here

But this shows a "normal" result by just dumping the output to stdout

git show-ref --tags --heads

which is what I prefer:

enter image description here

How to make all output be just dumped to stdout?

I'd prefer if all commands work the same way. Esp if I want to automate a git command in a batch script or something, I cannot use some kind of interactive shell.

I noticed that this behavior seems to be caused by the TERM=msys environment variable setting, which, if absent, behaves the same. I don't know if there's a different setting I can use.

In the end, while the colored result may be fun, I can get that by using Git BASH. But when I run the commands directly from the Windows Command, I'd expect them all to just echo the output to stdout.

I can't remember that this was the behavior previously, so my guess is that I installed something that f'ed things up ;). I'm on Windows 10 for this machine, git, bash etc are latest.

Abel
  • 56,041
  • 24
  • 146
  • 247
  • 1
    "I've no idea what key-combinations to use to scroll through the output": like vim, you can use j or k for up and down a line. Spacebar takes you down a page. b takes you up a page. q quits. – Tryer Mar 30 '22 at 15:24
  • https://stackoverflow.com/search?q=%5Bgit%5D+branch+behave+like+less – phd Mar 30 '22 at 15:34
  • @Tryer, tx! Last time I used VI(M) was in the early 90s I think, and while I did google for the commands, I couldn't find the correct manpage... Apparently it is called `less`. This helps :). – Abel Mar 30 '22 at 15:59
  • @phd, haha, indeed, if you _know_ that the command it is internally behaving as is called `less` I'd for sure have found it. So much for my non-existing unix skills! – Abel Mar 30 '22 at 16:07

1 Answers1

1

This is what git calls a pager. You can disable it for a particular command with:

git --no-pager branch -a

(Note that --no-pager goes between git and the subcommand, because it is a global switch).

If you want to configure your system so you don't have to remember that, from man git-config:

pager.<cmd>

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.<cmd>. 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.

That is, you can disable the pager for git-branch only with git config --global pager.branch false, for example.

And if you want to disable it for all commands do git config --global core.pager cat. Or you can try to set the environment variable GIT_PAGER=cat, of course.

rodrigo
  • 94,151
  • 12
  • 143
  • 190
  • Excellent, this works like a charm! If only I knew what terms to use for googling :D. I used `git config --global --add core.pager cat` to set it globally, which seems to work. – Abel Mar 30 '22 at 15:57