When you use git it seems to magically know whether standard out is going through a pipe or into a file vs when it is being displayed to the console. For example, if you have colors enabled and you do
git status
it will colorize the output for different categories of files being listed. However, if you do
git status | less
or
git status > status.txt
it removes the linux color formatting and you only see plain, uncolored text.
How does git
detect whether the output of its commands are going to file vs going to the terminal?