Last Updated: September 23, 2016
·
1.067K
· applitect

Add git name branch to prompt on MacOS

To get the command line tools installed, you may need to
$ xcode-select --install

Then add this to your .bash_profile

GIT_PS1_SHOWUPSTREAM="auto"
GIT_PS1_SHOWCOLORHINTS="yes"
. /Library/Developer/CommandLineTools/usr/share/git-core/git-completion.bash
. /Library/Developer/CommandLineTools/usr/share/git-core/git-prompt.sh
#PROMPT_COMMAND="parse_vcs_branch2; $PROMPT_COMMAND"
PROMPT_COMMAND='__git_ps1 "$(networksetup -getcomputername):[\w]" "\\\$ ";'
PS1='__git_ps1 "\h:[\w]" "\\\$ ";'

1 Response
Add your response

Nice.

And if you want some more informations, you can add:

export GIT_PS1_SHOWDIRTYSTATE=1
export GIT_PS1_SHOWSTASHSTATE=1

With that, after the branch name, you will have:
- a * if you have local unstaged changes
- a + if you have staged changes
- a $ if your stash stack is not empty

over 1 year ago ·