I want my git prompt in bash to colorize (green for clean repos, red for dirty repos). Right now, it shows plain white text no matter the git state of my cwd/repo.


  • The output of git is coloured by default. Which version do you have? Have you installed it from the repos? – Luís de Sousa Jul 8 '14 at 7:14
  • git 1.9.1 from official Ubuntu repos – apenneb Jul 29 '14 at 13:21

Although there could be a problem in /etc/bash_completion.d/git-prompt, I think you need to wrap PS1=... into a function and set PROMPT_COMMAND. See https://github.com/sengaya/configs-and-scripts/blob/master/.bashrc#L104 and https://github.com/sengaya/configs-and-scripts/blob/master/.bashrc#L16 for an example.

| improve this answer | |

Add this lines to file .gitconfig in your $HOME (create it if it does not exist):

    ui = auto

Or, alternatively, change it with the git config command:

$ git config --global color.ui auto

Optionally, leave out --global to apply it only to the current Git repository.

| improve this answer | |
  • The git info in the prompt has the color but the rest of the string that shows bash info loses the color though. – padfoot Dec 26 '16 at 11:02

Be sure git will use color with:

git config --global color.ui auto

Using bash and with git installed from the up-to-date package (1.9.1-1).

Add the following to .bashrc and then restart bash:

PROMPT_COMMAND='__git_ps1 "\u@\h:\w" "\\\$ "'

You don't need to change your .bashrc file as in the link you posted. That file eventually will be sourced anyway.

See /etc/bash_completion /usr/share/bash-completion/bash_completion /etc/bash_completion.d/git-prompt and, more importantly, /usr/lib/git-core/git-sh-prompt on your system for comments that describe the uses of the above variables (and additional ones).

Changes in already tracked file cause the dirty displays--newly added ones don't. The describe part of the prompt is only displayed when on a detached HEAD.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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