I have this command:

git stash list --pretty="%C(yellow)%h %>(14)%Cgreen%cr %C(blue)%gs"

gives output colored, but if I pipe it git stash list <..> | less -R, color disappear in output.

How to persist color of git stash list via pipe?


This is a feature, because git doesn't know what you are piping to.

You can configure the command to always output colors like this:

git -c color.ui=always your command | less -R

man git:

  -c <name>=<value>
      Pass a configuration parameter to the command. The value given will
      override values from configuration files. The
      <name> is expected in the same format as listed by git config
      (subkeys separated by dots).

Another option is to configure core.pager:

git config core.pager "less -R"

So you don't need to pipe to less yourself.


The right command should be:

git stash list --color=always --pretty="%C(yellow)%h %>(14)%Cgreen%cr %C(blue)%gs"

Add option --color=always

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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