How to read output from git pull –stat with colors into variable

How can I read stdout from git pull with colors into a bash variable?

Escaped sequences from ls --color=always are easily read into $output:

$ output=$(ls --color=always)
$ echo -e "$output"

But not from git pull --stat:

$ git config color.ui always
$ output=$(git pull --stat <repository> <refspec>)
$ echo -e "$output"

In other words, how can I trick git pull into thinking that it is not going to output into a variable? This does not work: $ env TERM=xterm-color git pull --stat.

  • Redirect all output to file
  • git commands not respecting io redirection
  • How to suppress stderr output in Powershell?
  • git fetch --quiet is writing to stdout instead of bieng silent
  • Git: unable to redirect/parse the output of 'git fetch --dry-run' command
  • Trying to redirect 'git gc' output
  • One Solution collect form web for “How to read output from git pull –stat with colors into variable”

    You have a typo in your config variable, it should be color.ui, singular, not colors.ui.
    On my system with git version 1.7.10 it then works as expected.

    Update: see screenshot:

    Git Baby is a git and github fan, let's start git clone.