3

How to colorize the branch name (shown in bold below) in the output of git checkout?

(base) dollaween $ git checkout develop
Switched to branch 'develop'
mkrieger1
  • 19,194
  • 5
  • 54
  • 65
  • You could probably do something with `sed` where you surround the single quotes in the escape characters that set terminal colors. But you would have to do that every time you `git checkout`, or write a function/script that wraps `git checkout`. – 0x5453 Dec 11 '20 at 13:41

1 Answers1

2

Color settings for different commands are controlled by the config variables

color.<command>.<slot>

You can see all available config variables with the command git help -c (see git config: list all variables and their default values). If there is no variable called color.checkout.… then I think this is not possible.

The closest replacement I could think of would be to colorize the branch name in the output of git status.

For example:

$ git config color.status.branch red
$ git status
On branch master
Your branch is up to date with 'origin/master'.
[…]

The bold part would now be red.

mkrieger1
  • 19,194
  • 5
  • 54
  • 65
  • _then I think this is not possible._ - If I understand C code correct, `git checkout` does not support what the OP wants: https://github.com/git/git/blob/e31aba42fb12bdeb0f850829e008e1e3f43af500/builtin/checkout.c#L927 as it seems to print the branch name only. – terrorrussia-keeps-killing Dec 11 '20 at 16:06
  • Unfortunately, it doesn't work( This work for `git status`, but not for `git checkout` – Maks Endless Dec 11 '20 at 20:10
  • That's what I wrote. Unfortunately, I don't know another way. – mkrieger1 Dec 11 '20 at 20:10