Output the color of a specific git command

I am writing a tool that runs git commands and captures the output, and I want the color to be highlighted. git notices that the tool is not a terminal, so color.ui needs to be set to always . I really don't want to install this in the global / repo configuration file, since it will work with other programs using git. git book does not explicitly encourage this:

You rarely want color.ui = always. In most scenarios, if you need color codes in your redirected output, you can instead pass the -color flag to the git command to force it to use color codes. The value color.ui = true is almost always used by you.

Unfortunately, not all git commands support the --color flag, especially git status and git pull .

So how can I force colors for a single git command? Is it possible to configure a configuration variable, for example. for custom git configuration file?

0
git
Apr 16 '14 at 11:04
source share
2 answers

You can use the -c option to override configuration values. This works for all git commands. For example:

 git -c color.ui=always status > status_file 

outputs color codes to a file. He does not see pty, so he will not try to paginate.

0
Dec 11 '14 at 19:35
source share

I think you should use the PTY master / slave to communicate with the git subcommand instead of the channel. This means that git considers it to be running in an interactive session, and not in the pipeline.

+1
Apr 16 '14 at 11:16
source share



All Articles