Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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.

https://github.com/mcandre/dotfiles/blob/master/.bashrc-wi#L135-L138

share|improve this question
    
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 at 7:14
    
git 1.9.1 from official Ubuntu repos –  apenneb Jul 29 at 13:21

3 Answers 3

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.

share|improve this answer

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

[color]
    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.

share|improve this answer

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" "\\\$ "'
GIT_PS1_DESCRIBE_STYLE='describe'
GIT_PS1_SHOWDIRTYSTATE=1
GIT_PS1_SHOWCOLORHINTS=1

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.

share|improve this answer

Your Answer

 
discard

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.