How to Color the Git Console

John Wachira Feb 02, 2024
  1. Git color.ui
  2. Git Color Values
  3. Git Color Configuration
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.

  1. current: This refers to the current branch.
  2. local: Refers to a local branch in our repository.
  3. remote: Refers to remote branch reference in ref/remotes.
  4. upstream: Refers to an upstream tracking Git branch.
  5. plain: Any other ref.

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.

  1. context: This refers to the lines of text content displayed in a diff or patch to show changes.
  2. plain: This is a synonym for context.
  3. meta: Refers to the meta-information on the git diff.
  4. frag: Points to the hunk header or the function present in the hunk header.
  5. old: Points to the removed lines of code in the diff.
  6. new: Points to the added lines of code in the diff.
  7. commit: Refers to the commit headers in the diff.
  8. whitespace: Set a color for whitespace errors in the git 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.

  1. header: Points to the header content of the status display.
  2. added or updated: Both target any added but not committed files.
  3. changed: This points to the modified files that are not added to the index.
  4. branch: Points to the current branch.
  5. untracked: Points to all untracked files.
  6. 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.

  1. context: Points to the non-matching text in our context lines.
  2. filename: Points to the filename prefix.
  3. function: Points to the function name lines.
  4. linenumber: Points to the line number prefix.
  5. match: Refers to the matching text.
Author: John Wachira
John Wachira avatar John Wachira avatar

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