Book Image

Git Version Control Cookbook

Book Image

Git Version Control Cookbook

Overview of this book

Table of Contents (19 chapters)
Git Version Control Cookbook
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

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

aske@yggdrasil:~/cookbook-tips-tricks$

We...