64

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?

Ciro Santilli OurBigBook.com
  • 347,512
  • 102
  • 1,199
  • 985
thewillcole
  • 2,943
  • 3
  • 30
  • 35
  • 1
    Starting git1.8.4, you should see colors by default. See [my answer below](http://stackoverflow.com/a/17276866/6309). – VonC Jun 24 '13 at 13:36
  • possible duplicate of [How to configure Mac OS X term so that git has color?](http://stackoverflow.com/questions/1156069/how-to-configure-mac-os-x-term-so-that-git-has-color). The question I'm linking to is closed but it covers the same ground and was asked before this. – Tony Oct 16 '13 at 21:57
  • Possible duplicate of [How to color the \`git\` console?](https://stackoverflow.com/questions/10998792/how-to-color-the-git-console) – Trevor Boyd Smith Jul 17 '18 at 14:59

7 Answers7

111
git config --global color.ui auto
rob mayoff
  • 375,296
  • 67
  • 796
  • 848
14

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
DemitryT
  • 391
  • 4
  • 17
9

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

Sam
  • 1,623
  • 1
  • 19
  • 31
5

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

Ivan Smirnov
  • 51
  • 1
  • 2
3
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
3

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.
Dave Sag
  • 13,266
  • 14
  • 86
  • 134
1

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".

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250