There's more...

What is a terminal without some colors these days? The git-prompt.sh script also supports this. All we need to do is set the GIT_PS1_SHOWCOLORHINTS variable to a nonempty value and, instead of using PS1, we need to use PROMPT_COMMAND. Let's change ~/.bashrc:

export GIT_PS1_SHOWUPSTREAM=auto
export GIT_PS1_SHOWDIRTYSTATE=enabled
export GIT_PS1_SHOWCOLORHINTS=enabled
PROMPT_COMMAND='__git_ps1 "\u@\h:\w" "\$ "'

If we redo the same scenario as the previous one, we get the following:

Get Git Version Control Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.