Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Is there a way to color output for git (or any command)?


baller@Laptop:~/rails/spunky-monkey$ git status
# On branch new-message-types
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#       modified:   app/models/message_type.rb
no changes added to commit (use "git add" and/or "git commit -a")
baller@Laptop:~/rails/spunky-monkey$ git add app/models


baller@Laptop:~/rails/spunky-monkey$ git status
# On branch new-message-types
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#       modified:   app/models/message_type.rb

The output looks the same, but the information is totally different: the file has gone from unstaged to staged for commit.

Is there a way to colorize the output? For example, files that are unstaged are red, staged are green?

Or even Changes not staged for commit: to red and # Changes to be committed: to green?

Working in Ubuntu.

EDIT: Googling found this answer which works great: git config --global --add color.ui true.

However, is there any more general solution for adding color to a command output?

share|improve this question
You want something that colorizes all command outputs? How would it know which parts to color? –  Michael Mrozek Jul 30 '12 at 0:28
I guess if there was a way to configure it using regex: Each color could have a start regex. And there could be a default color regex to turn off all colors. And, if text "foo" appears, display it in a certain color... –  B Seven Jul 30 '12 at 0:33

4 Answers 4

up vote 37 down vote accepted

You can create a section [color] in your ~/.gitconfig with e.g. the following content

  diff = auto
  status = auto
  branch = auto
  interactive = auto
  ui = true
  pager = true

You can also fine control what you want to have coloured in what way, e.g.

[color "status"]
  added = green
  changed = red bold
  untracked = magenta bold

[color "branch"]
  remote = yellow

I hope this gets you started. And of course, you need a terminal which supports colour.

share|improve this answer

You probably want to use

git config --global color.ui auto

The auto part says that git will only try and use color on terminals that support it, and you will not get ansi sequences if you redirect output of git commands to a file for example.

The color.ui is a meta configuration that includes all the various color.* configurations available with git commands.

This is explained in-depth in git help config.

share|improve this answer

I enjoy using this although I haven't figured out how to work around a bug where prompts expecting input aren't shown and you can't simply type the known needed input and press enter to continue in every case. Arbitrary Command Output Colourer http://www.caliban.org/ruby/acoc.shtml

share|improve this answer

Try printing the following to the terminal from a script: \033[35m your_text_here \033[0m

The text should be displayed in purple. Then you can just capture the output of the shell commands and wrap it as above. A list of colors can be found here: http://SynOdins.com/programs/terminal_fonts/

So, for example, in: /usr/lib/git-core/git-am

echo "\033[35m$(eval_gettext "Applying: \$FIRSTLINE")\033[0m"

rather than

say "$(eval_gettext "Applying: \$FIRSTLINE")"

can speed up parsing the "git rebase" output (in case you need it -- to resolve conflicts).

share|improve this answer
Too hackish considering this can be configured in git. –  Hugo Jul 30 '12 at 15:13
Yeah but that's a git only solution. This solution works for all shell commands, including git. –  Hermann Ingjaldsson Jul 30 '12 at 16:39
You can then wrap this solution into aliases and functions which makes this end up as a non-hackis, non-git-only solution. –  Hermann Ingjaldsson Nov 26 '12 at 13:28

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.