Why is less being run unnecessarily by git

git

When I run git branch (from bash or csh), it automagically pipes the output through less. However, with only a few branches in the repository this is beyond unnecessary, it is annoying, as the branch listing disappears once I quit less.

Checking ~/.gitconfig file and the local .git/config files finds nothing about a pager or any thing else that would cause this. Otherwise, nothing I've found in web searches has been helpful or promising.

Why is this happening, and what (if anything) can I do to make less run when needed (e.g. when doing a git log when there's a lot of history) but not otherwise (like a git branch with only 2 or 3 branches)?

Best Answer

You can set the following:

git config --global core.pager 'less -FRX'

This will ensure that less will

  • Exit if the entire file can be displayed on the first screen (F)
  • Output the raw control characters for terminal formatting (R)
  • Chop long lines (S)
  • Don't send the init/de-init strings to the terminal - avoids clearing the screen on exit (X)

Edit: Removed the S option based on Peter A. Scheider's comment

Related Question