33

So I have my gitconfig setup to do colors. In Terminal it works great, looks fine.

In iTerm2, however, the colors don't appear for my gitconfig at all unless I set the reverse property for git. Then they appear but who likes reversed colors anyways?

Why does this happen and how can I fix it?

Robert Ross
  • 1,895
  • 2
  • 23
  • 32

4 Answers4

51

You should check that iTerm is setting the TERM variable correctly. On my system, I see:

echo $TERM
xterm-256color

And have working colours in git. This is set according to the 'Report Terminal Type' property in iTerm's preferences.

here's a screenshot of iTerm 2's preferences

You should also check the Colors tab, and ensure the contrast slider isn't all the way to the right.

Matt
  • 5,522
  • 5
  • 29
  • 24
  • 1
    Odd, I've tried that. I'm still seeing the escape codes from git log output: ESC[33mcommit e56f9a33b767f551568ESC[m $ echo $TERM xterm-256color – Public Profile Dec 07 '11 at 21:21
  • 3
    I'm guessing you have figured this out by now :) but in case others face the same problem and the above does not help: your problem is probably related to the pager (less), not to git. [A solution is available at the Unix&Linux StackExchange](http://unix.stackexchange.com/a/64932/40740). – Eric Hansander Oct 13 '13 at 04:32
  • 8
    +1 for "You should also check the Colors tab, and ensure the contrast slider isn't all the way to the right." – Nick Woodhams Oct 26 '13 at 07:58
37

In my case I had coloured output from other terminal applications in iTerm, just not git. For anyone still looking to solve this, what did it for me was the solution from http://buildamodule.com/forum/post/iterm-git-ui-colors.

Modify your global git config as follows:

git config --global color.ui true

FlintZA
  • 872
  • 1
  • 11
  • 22
  • my iTerm became absolutely pretty. :) – Sakares Jun 29 '13 at 03:27
  • 1
    Oddly enough, `git log --color` worked, but for `color "diff"`, I needed this extra. –  Mar 14 '16 at 03:06
  • This got it working by prompting me to agree to Xcode License agreement again, I guess updating caused things to not work until re-agreeing. – Scott Sep 27 '16 at 17:25
3

I found an answer to this via http://code.google.com/p/iterm2/issues/detail?id=1639 that works for me.

"The solution is to add this to your ~/.gitconfig "

[core]
    pager = less -R
dajobe
  • 4,938
  • 35
  • 41
2

For me this was not a git issue, but it was an iTerm2 issue on macOS. I ended up solving this by going to the iTerm2 Preferences > Window > Check the "Keep background colors opaque" checkbox and should now have no more pain or sorrows! #RevDev

enter image description here

timSully
  • 137
  • 1
  • 11