How to colorify git errors, warnings and fatal messages?

When troubleshooting git issues of users, I keep running into people not noticing error/warning messages from git, and then burning their fingers. Is there any way to colorify errors and warnings git outputs?

  • git-p4: Can't Map File error
  • What's recommended .gitignore for Scala/sbt project in IntelliJ IDEA?
  • Libgit2sharp Unit Test
  • “The program 'rails' is currently not installed” after git clone
  • Extracting only open issues from github api without any pull request using ruby on rails
  • Subversion and GIT centralization
  • eGit move project to a different location?
  • How to edit commit message of a pushed git commit
  • 3 Solutions collect form web for “How to colorify git errors, warnings and fatal messages?”

    There is no git buit-in way to do that. Git just prints errors to STDERR and doesn’t care about the fatality of the error or anything. What you can do is color STDERR red. How to do this has been asked on on ServerFault:

    There are three basic options:

    1. Run your command like this:

      *git-command* 2> >(while read line; do echo -e "\e[01;31m$line\e[0m" >&2; done)
    2. Use a wrapper script (See ServeFault for those), and run commands like

      mywrapper *git-command*
    3. Install stderred. This will allow you to make the effect permanent, without modifying your command line. Not sure whether this will work on windows, though.

    Since I didn’t find a suitable way to color error messages, my solution is to add an additional warning when git returns an error code (!=0).

    To do it, add this to your ~/.bashrc or ~/.bash_profile

    # Wrap git. On errors, print an additional line in red.
        command git "$@"
        local exitCode=$?
        if [ $exitCode -ne 0 ]; then
            printf "\033[0;31mERROR: git exited with code $exitCode\033[0m\n"
            return $exitCode

    Here is the result:
    enter image description here

    Note that coloring stderr in red does not work very well because git logs many things in stderr, not only errors. And some errors are output in standard output.

    You can use the color config section of git.

    For more information and examples see or the second part of

    example: (add to your .gitconfig)

         interactive = always
    [color "interactive"]
         error = red bold
    Git Baby is a git and github fan, let's start git clone.