Book Image

Git Version Control Cookbook

By : Aske Olsson, Rasmus Voss
Book Image

Git Version Control Cookbook

By: Aske Olsson, Rasmus Voss

Overview of this book

Table of Contents (19 chapters)
Git Version Control Cookbook
About the Authors
About the Reviewers

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,, 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 file:

if [ -f /etc/bash_completion.d/ ]; then
    source /etc/bash_completion.d/

How it works…

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

PS1='\u@\h:\w\$ '

The preceding command shows the current user, an @ sign, the host name, the current working directory relative to the user's home directory, and finally a $ character: