Question

I'm using the Git Bash in Windows and for the purposes of my custom git log format, I'd like to modify the terminal's exact RGB color values so I can fine-tune the color outputs. My git log format is as follows in my global .gitconfig:

lg1 = log --graph --abbrev-commit --decorate --date=relative --format=format:'%C(bold blue)%h%C(reset)%x09%C(bold green)(%ar)%C(reset)%C(bold yellow)%d%C(reset) %C(dim white)%an%C(reset) - %C(white)%s%C(reset)' --branches --remotes --tags

I'd like to define in Git Bash what RGB value actually maps to 'blue', for example. Any idea how I can do this? Step by step instructions would be wonderful. Thanks in advance.

EDIT

I setup my .bashrc and it isn't working for some reason. Colors aren't changing :-(. Here is a script I ran to see colors: http://pastebin.com/9EsYmGCj and the result: http://i.imgur.com/1dJ3o1a.png

Was it helpful?

Solution

This works for me to change the text colors used by Git Bash on Windows 7:

  • Click on the upper left corner of an open Git Bash window (the Git icon in the window frame).
  • A menu appears (the same that would appear with a regular DOS cmd Window). Choose the last entry: "Properties", UPDATE 2021: "Options..." (thanks AlexD!)
  • Go to tab "Colors"
  • Choose radio button "Screen Text"
  • Remember which color is currently assigned to "Screen Text" in the row of small color boxes (it has a black frame).
  • Then select the color you want to change by clicking on the corresponding color box. This color is now assigned as "Screen Text", which is what Git Bash uses for regular text. But don't worry, this change is only temporary and needed to modify the value of a color.
  • Now change the Red/Green/Blue values for the selected color. In my case I wanted to make the fifth color from the left (much) brighter. Let's call it "Color 5". This is the color Git Bash uses to show changed files with "git status". Whenever Git Bash wants to use "Color 5" it will use the new RGB value.
  • "Screen Text" is now still set to "Color 5". So click on the original color that you have remembered.

The changes made in this way are permanent but only valid for the shortcut you have used to start Git Bash. If you create a new shortcut you are back to the original colors.

OTHER TIPS

If you are using the git-bash command prompt check if you have the file: %USERPROFILE%\.minttyrc
In that file you can fine tune the RGB values of the console colors in this way:

BoldBlack=128,128,128
Red=255,64,40
BoldRed=255,128,64
Green=64,200,64
BoldGreen=64,255,64
Yellow=190,190,0
BoldYellow=255,255,64
Blue=0,128,255
BoldBlue=128,160,255
Magenta=200,64,255
BoldMagenta=255,128,255
Cyan=64,190,190
BoldCyan=128,255,255
White=200,200,200
BoldWhite=255,255,255

For those of you coming here to get an answer to the actual Original Question the answer is to add the following line to the end of:

C:\Program Files\Git\etc\profile.d\git-prompt.sh

LS_COLORS=$LS_COLORS:'di=1;30:' ; export LS_COLORS

You may chose from these colors.

Black       0;30     Dark Gray     1;30
Blue        0;34     Light Blue    1;34
Green       0;32     Light Green   1;32
Cyan        0;36     Light Cyan    1;36
Red         0;31     Light Red     1;31
Purple      0;35     Light Purple  1;35
Brown       0;33     Yellow        1;33
Light Gray  0;37     White         1;37

Git bash uses the default Windows console colors which may be tweaked in the registry. E.g. to increase readability, one can change the dark red and the dark magenta to a lighter version by applying the changes as indicated below:

Windows Registry Editor Version 5.00
; Default color scheme
; for Windows command prompt.

; Values stored as 00-BB-GG-RR
[HKEY_CURRENT_USER\Console]
; BLACK DGRAY
"ColorTable00"=dword:00000000
"ColorTable08"=dword:00808080
; BLUE LBLUE
"ColorTable01"=dword:00800000
"ColorTable09"=dword:00ff0000
; GREEN LGREEN
"ColorTable02"=dword:00008000
"ColorTable10"=dword:0000ff00
; CYAN LCYAN
"ColorTable03"=dword:00808000
"ColorTable11"=dword:00ffff00
; RED LRED --> To increase readability, use e.g. 000000aa for "ColorTable04"
"ColorTable04"=dword:00000080
"ColorTable12"=dword:000000ff
; MAGENTA LMAGENTA --> To increase readability, use e.g. 00aa00aa for "ColorTable05"
"ColorTable05"=dword:00800080
"ColorTable13"=dword:00ff00ff
; YELLOW LYELLOW
"ColorTable06"=dword:00008080
"ColorTable14"=dword:0000ffff
; LGRAY WHITE
"ColorTable07"=dword:00c0c0c0
"ColorTable15"=dword:00ffffff

When using MSYSGIT, Git Bash runs in the Windows Command Prompt. Consequently, it uses the colors defined for the terminal. Since Git Bash is a command that is always run, you can set its colors in the Command Prompt's Properties, rather than Defaults.

For instructions on changing the terminal colors, see: https://superuser.com/questions/199764/how-to-change-the-default-color-of-the-command-prompt


Note: I've found the Command Prompt's color options to be a huge pain to configure, as they frequently changed/reset while editing. The trick seems to be to tab out of the input boxes after editing.

Since those color names are linked to ANSI escape codes (as I mentioned in a previous answer), you can try the approach described in this issue:

Just add these to your .bashrc

echo -ne "\e]4;4;#007fff\a"  # 4;4 is Dark Blue #005FFF

(pick an rbg value which seems more readable to you for color blue, or choosing from this palette)

2017 Update Open Gitbash and click the icon in the upper left corner and select "Options"

From the options menu you can configure transparency, foreground color (text), background color, and cursor color. Pretty straightforward and easy.

Windows10 + GitBash: Warning Message Samples


The following samples will print out a red background with white text.

Original colors are RESTORED after the print.


Echo One Line Message:

MSG="MY_WARNING_MESSAGE_TEXT" BG="41m" FG="1m"
echo -en "\033[$FG\033[$BG$MSG\033[0m\n"

Block Of Colored Text with HARDCODED message:

BG="41m" FG="1m"
HD_CAT_VAR=$(cat << 'HEREDOC_CAT_VAR_REGION'
+-------------------------------------+
|                                     |
|     HARD_CODED_WARNING_MESSAGE      |
|                                     |
+-------------------------------------+
HEREDOC_CAT_VAR_REGION
)
echo -en "\033[$FG\033[$BG$HD_CAT_VAR\033[0m\n"

Block of Colored Text with VARIABLE message:

VARIABLE_WARNING_MESSAGE="OH_NOOOOOO!"
BG="41m" FG="1m"
HD_CAT_VAR=$(cat << HEREDOC_CAT_VAR_REGION
+-------------------------------------+
|                                     |
+-------------------------------------+
      $VARIABLE_WARNING_MESSAGE        
+-------------------------------------+
|                                     |
+-------------------------------------+
HEREDOC_CAT_VAR_REGION
)
echo -en "\033[$FG\033[$BG$HD_CAT_VAR\033[0m\n"

To change the windows console color, you can use Microsoft's Colortool:

The colortool will work with any .itermcolors scheme.

https://blogs.msdn.microsoft.com/commandline/2017/08/11/introducing-the-windows-console-colortool/

Github: https://github.com/Microsoft/console/tree/master/tools/ColorTool

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top