1

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

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

3 Answers 3

1

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.

1

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.

1
  • 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, 2016 at 11:02
0

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .