Add Git Branch Name to Terminal Prompt (Mac)


Thank you for your tip. I added your function into my own custom prompt:

PS1="$NO_COLOUR[\t] $BLUE\u$SSH_FLAG:$YELLOW\w$NO_COLOUR: \n$GREEN\$(parse_git_branch) $BLUE\\$ $NO_COLOUR"

However it showed the repository with bracket, like this: [13:11:22] user:~/git/folder: (master) $

Any idea how to remove the brackets?


I guess that you are calling ‘bracket’ to the parentheses surrounding the branch name, right? They are coming from the regular expression in the function. To remove them (or make that whatever you fancy), go to the parse_git_branch function and look for:

[...] -e 's/* \(.*\)/ (\1)/' and remove (or replace) the parentheses around the \1, so as an example, it would be: [...] -e 's/* \(.*\)/ \1/' if you wanted the branch name with just a blank separating it from the current dir.

I hope it’s clear!


Thank you very much for your answer. It works perfectly!


Awesome. Thanks a lot!


I had been looking for this from months, and i found it today, wondering how did i miss this article, Its working great! Thanks a lot.