I'm trying to add my current git branch to my bash terminal prompt. I've copied this file: https://github.com/git/git/blob/master/contrib/completion/git-prompt.sh to my home directory and this is the part of .bashrc that relates to my prompt:
source ~/.git-prompt.sh
if [ "$color_prompt" = yes ]; then
PS1='${debian_chroot:+($debian_chroot)}\[\033[32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00;31m\] \W$(__git_ps1 " (%s)")\[\033[00m\]\$ '
else
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\ \W$(__git_ps1 " (%s)")$ '
fi
However, \W$(__git_ps1 " (%s)") is returning the current folder and the branch, and returns the current directory when not in a repository.
Is it possible to get it to only display the current branch when in a repository and when I'm not in one, display nothing?