Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get git to show colored output during hook output?

Tags:

git

ssh

I'm currently using git to deploy a project, and I was wondering how I could get the output of tools like npm and gulp to be in color in the same that they are when using those tools locally?

For example

enter image description here

vs

enter image description here

like image 211
rtheunissen Avatar asked Oct 16 '25 13:10

rtheunissen


2 Answers

The short answer: either force colored output for each tool used in git hooks on the remote side or forcibly set TERM environment variable (again, on the remote side). Use export TERM=xterm (or export TERM=xterm-color) somewhere in the beginning of each hook script.

The long answer: by default unix tools like npm or git itself generate colored output (i.e. output with extra escape-sequences which change color accordingly) only if these tools can detect that terminal in which they operate is capable to change colors. Terminal capabilities is defined via environment variable TERM. Ordinary, interactive SSH sessions can transfer TERM value to a remote side (see Can I forward env variables over ssh?) but non-interactive sessions usually don't do this, non-interactive sessions may operate in TTY-less mode. You can force usage of color for a particular tool (e.g. npm via config) or configure TERM environment variable properly.

like image 167
user3159253 Avatar answered Oct 18 '25 10:10

user3159253


On your remote server

type in

git config --global color.ui auto  

That should give you color

like image 39
yokodev Avatar answered Oct 18 '25 12:10

yokodev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!