Bash prompt with status information

Another cool feature Git provides is to have the prompt display status information if the current working directory is a Git repository.

Getting ready

For the status information prompt to work, we also need to source another file, git-prompt.sh, which is usually distributed with the Git installation and located in the same directory as the completion file.

How to do it...

In your .bashrc or .zshrc file, add the following code snippet, again depending on your shell and the location of the git-prompt.sh file:

if [ -f /etc/bash_completion.d/git-prompt.sh ]; then
    source /etc/bash_completion.d/git-prompt.sh
fi

How it works…

To make use of the command prompt, we must change the PS1 variable; usually this is set to something ...

Get Git: Mastering Version Control 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.