I'm writing a tool that runs git commands and captures the output, and I'd like to have the output colored. Git notices that the tool isn't a terminal, so the color.ui
would need to be set to always
. I don't really want to set this in the global/repo configuration file, as it would mess with other programs using git. The git book explicitly discourages that, too:
You’ll rarely want color.ui = always. In most scenarios, if you want color codes in your redirected output, you can instead pass a --color flag to the Git command to force it to use color codes. The color.ui = true setting is almost always what you’ll want to use.
Sadly, not all git commands support the --color
flag, most notably git status
and git pull
.
So, how do I force colors for one git command? Is there a configuration variable I can set, e.g. for a custom git config file?