After searching the net, I found that one can display the git branch name with the PS1 with below
PS1="$(__git_ps1 ) "
While this is working fine, and it display the branch name in PS1 prompt. But it is displayed where-ever I navigate, even outside the git-checked-out-repo.
I would like to display the branch name only if I am under a git tracked folder/repo. Any way to achieve this? Searching SO and net didn't pop-up helpful links in this respect.
You need to defer execution of
$(__git_ps1)
untilPS1
is actually displayed. Use single quotes: