How to Color the Git Console
This article will discuss how we can configure our Git terminal to have a colored output. We can customize the terminal to our liking for easier use.
We will use the git config
command to set the color values. Let’s start.
Git color.ui
The Git color.ui
refers to the master variable when dealing with Git colors. To disable colors in our Git terminal, we will have to set it to false
, as shown below.
$ git config --global color.ui false
A fresh Git terminal has the variable set to auto
. This gives the immediate terminal output stream colors and omits color code for outputs piped to another process or directed to a file.
We can set it to always
to include the exemptions above; however, we may run into problems when the receiving pipe is not expecting colored input.
$ git config --global color.ui always
Git Color Values
Besides color.ui
, Git also supports other granular color configurations that can be set to always
, auto
, and false
. These settings have a specified color value.
Git supports color values like normal, black, red, green, yellow, blue, magenta, cyan, and white.
We can use hexadecimal color codes like #ff0000
to specify the color if our terminal supports it.
Git Color Configuration
1. color.branch
We use this command to configure the output color of the git branch
command. We can use it in the following context.
$ git config --global color.branch <slot>
The <slot>
can be any of the following.
current
: This refers to the current branch.local
: Refers to a local branch in our repository.remote
: Refers to remote branch reference inref/remotes
.upstream
: Refers to an upstream tracking Git branch.plain
: Any otherref
.
2. color.diff
We use this command to configure the output colors for the git diff
, git log
, and git show
commands. We can use it as shown below.
$ git config --global color.diff <slot>
The <slot>
can be any of the following.
context
: This refers to the lines of text content displayed in adiff
or patch to show changes.plain
: This is a synonym forcontext
.meta
: Refers to the meta-information on thegit diff
.frag
: Points to the hunk header or the function present in the hunk header.old
: Points to the removed lines of code in thediff
.new
: Points to the added lines of code in thediff
.commit
: Refers to the commit headers in thediff
.whitespace
: Set a color for whitespace errors in thegit diff
.
3. color.status
This Boolean value configures or disables color-coded output for the git status
command. We can use it in the context below.
$ git config --global color.status <slot>
The <slot>
can be any of the following.
header
: Points to the header content of the status display.added
orupdated
: Both target any added but not committed files.changed
: This points to the modified files that are not added to the index.branch
: Points to the current branch.untracked
: Points to all untracked files.unmerged
: Points to files with unmerged changes.
4. color.grep
This command will apply color to our git grep
output. We can use it in the context below.
$ git config --global color.grep <slot>
The <slot>
can be any of the following.
context
: Points to the non-matching text in our context lines.filename
: Points to the filename prefix.function
: Points to the function name lines.linenumber
: Points to the line number prefix.match
: Refers to the matching text.
John is a Git and PowerShell geek. He uses his expertise in the version control system to help businesses manage their source code. According to him, Shell scripting is the number one choice for automating the management of systems.
LinkedIn