Enabling Git syntax highlighting for Mac's terminal

GitTerminalSyntax Highlighting

Git Problem Overview


I miss the Git syntax highlighting I had on Windows for every "git .*" command like green staged filenames, some bolding, etc.

How do I enable Git syntax highlighting for Mac's terminal?

Git Solutions


Solution 1 - Git

git config --global color.ui auto

Solution 2 - Git

For seeing different colors for the diff command, use:

git config --global color.diff true

To globally change colors for most commands, use:

git config --global color.ui true

Solution 3 - Git

Colors in Git

Git can color its output to your terminal, which can help you visually parse the output quickly and easily. A number of options can help you set the coloring to your preference.

color.ui

Git automatically colors most of its output if you ask it to. You can get very specific about what you want colored and how; but to turn on all the default terminal coloring, set color.ui to true:

$ git config --global color.ui true

When that value is set, Git colors its output if the output goes to a terminal. Other possible settings are false, which never colors the output, and always, which sets colors all the time, even if you’re redirecting Git commands to a file or piping them to another command.

You’ll rarely want color.ui = always. In most scenarios, if you want color codes in your redirected output, you can instead pass a --color flag to the Git command to force it to use color codes. The color.ui = true setting is almost always what you’ll want to use.

color.*

If you want to be more specific about which commands are colored and how, Git provides verb-specific coloring settings. Each of these can be set to true, false, or always:

color.branch
color.diff
color.interactive
color.status

In addition, each of these has subsettings you can use to set specific colors for parts of the output, if you want to override each color. For example, to set the meta information in your diff output to blue foreground, black background, and bold text, you can run

$ git config --global color.diff.meta "blue black bold"

You can set the color to any of the following values: normal, black, red, green, yellow, blue, magenta, cyan, or white. If you want an attribute like bold in the previous example, you can choose from bold, dim, ul, blink, and reverse.

See the git config manpage for all the subsettings you can configure, if you want to do that.

Reference : http://git-scm.com/book/ch7-1.html

Solution 4 - Git

I've used next solution:

git config --global color.diff auto
git config --global color.status auto
git config --global color.branch auto

Original article

Solution 5 - Git

git config --global color.diff true
git config --global color.status true
git config --global color.branch true
git config --global color.interactive true

There are 4 settings types available:

  • false - disabled
  • true - enabled, only in command prompt
  • always - enabled always

Solution 6 - Git

I found this excellent blog post that explains how to set up your git colours and what the standard colours are. In summary, add the following lines to your ~/gitconfig file: (Here's mine - pretty eh?)

[color]
  ui = auto
[color "branch"]
  current = auto
  remote = white reverse
[color "diff"]
  meta = yellow bold
  frag = magenta bold
  new = green bold
[color "status"]
  added = yellow bold
  changed = green
  untracked = cyan

In modern versions of Git the colour.ui setting is now auto by default.

You can use the following as colours:

  • normal,
  • black,
  • red,
  • green,
  • yellow,
  • blue,
  • magenta,
  • cyan, and
  • white.

You can also supply the following optional modifiers:

  • bold,
  • dim,
  • ul,
  • blink, and
  • reverse.

Solution 7 - Git

Note: starting git1.8.4 (June 2013), you won't have to do anything:

> Many tutorials teach users to set "color.ui" to "auto" as the first thing after you set "user.name/email" to introduce yourselves to Git.
Now the variable defaults to "auto".

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionthewillcoleView Question on Stackoverflow
Solution 1 - Gitrob mayoffView Answer on Stackoverflow
Solution 2 - GitDemitryTView Answer on Stackoverflow
Solution 3 - GitSamView Answer on Stackoverflow
Solution 4 - GitIvan SmirnovView Answer on Stackoverflow
Solution 5 - GitОлег КабановView Answer on Stackoverflow
Solution 6 - GitDave SagView Answer on Stackoverflow
Solution 7 - GitVonCView Answer on Stackoverflow