75

I want the output of git status to be returned in a less-like environment. This already works for git diff, but not git status. I already tried adding the following to ~/.gitconfig, but it didn't work:

[core]
  pager = less

What am I missing? Thanks.

user229044
  • 232,980
  • 40
  • 330
  • 338
Waldo000000
  • 853
  • 1
  • 6
  • 4
  • 1
    I don't know if there is a way to do it, but, is `git status | less` too difficult? You only really need it when you have a lot of modified files. – Eve Freeman Jan 16 '12 at 16:42
  • 3
    @WesFreeman it is a bit annoying than this. Git will not preserve colors when piped to less and there is no `--color=always` to `git status`. If there were such an option, the one would have to type `git status --color=always | less -R` - not so succinct, right? – brandizzi Apr 17 '13 at 18:40
  • 1
    This is also super useful now that we have `git status -vv`, which adds on `git-diff`'s output to the end. – Xiong Chiamiov Jul 10 '15 at 19:10
  • @EveFreeman "You only really need it when you have a lot of files" which is all the time in the project on which I'm working. Build artifacts number in the hundreds on this project, and the .gitignore is large, but doesn't cover them all. – lmat - Reinstate Monica Apr 16 '16 at 08:26

2 Answers2

114

You can turn on and off paging of specific commands with the pager.<cmd> setting, in this case pager.status:

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

Run the following to enable paging for status subcommand:

git config --global pager.status true

or manually add the following to the end of your ~/.gitconfig:

[pager]
    status = true

If you just want to turn paging on or off for a specific invocation, you can use option -p/--paginate respectively -P/--no-pager to the git command itself as well, e.g.:

git -p status
doak
  • 809
  • 9
  • 24
user229044
  • 232,980
  • 40
  • 330
  • 338
  • 4
    And this seems to preserve the colorization as well! Many thanks! – dsz Jan 15 '14 at 23:49
  • For the aim that one answer should answers all aspects, it would be nice to include the hint to `--paginate`/`--no-pager` here as well. – doak Feb 28 '21 at 13:00
  • Oh, I just overlooked it because it was "buried" within the documentation quote. My bad. – doak Feb 28 '21 at 13:10
12

For one-off:

git -p status

Or --paginate. Colourised. Works everywhere. Including errors/help.

git -p status -h is much better than having to grab stderr with git status -h |& less

Though long help messed up my terminal: git -p status --help

hyperpallium
  • 571
  • 5
  • 18