Show git branch name in terminal prompt

suggest change

You can have functions in the PS1 variable, just make sure to single quote it or use escape for special chars:

    gitps1=$(git branch 2>/dev/null | grep '*')
    gitps1="${gitps1:+ (${gitps1/#\* /})}"
    echo "$gitps1"

PS1='\u@\h:\w$(gitPS1)$ '

It will give you a prompt like this:

user@Host:/path (master)$


Feedback about page:

Optional: your email if you want me to get back to you:

Table Of Contents