Show git branch and status in Mac Bash

24,431

Solution 1

I think ohmyzsh is my best choose!

https://github.com/robbyrussell/oh-my-zsh

Solution 2

Git itself has this: https://raw.github.com/git/git/master/contrib/completion/git-prompt.sh

Usage sample:

GIT_PS1_SHOWUPSTREAM="auto"
GIT_PS1_SHOWCOLORHINTS="yes"
source ~/.git-prompt.sh

export PROMPT_COMMAND='__git_ps1 "\u@\h:\W" "\\\$ ";'

It looks like this:

enter image description here

The green name is the branch, the symbol before the closing parenthesis is the status.

Solution 3

vcprompt offers similar shell prompt for Git (and Hg, Bazaar and SVN). You can install it via homebrew:

brew install vcprompt
Share:
24,431
Dozer
Author by

Dozer

Updated on October 26, 2020

Comments

  • Dozer
    Dozer over 3 years

    I use the Github for windows client.The shell with powershell is very nice!

    enter image description here

    How do I implement it on MAC? Not only the branch name,I also want git status

  • Leigh  McCulloch
    Leigh McCulloch over 10 years
    You need to put djromero's usage sample into ~/.bash_profile. By default you probably won't have one on Mac, so you need to create the file and then use the above verbatim (assuming git-prompt.sh is saved at ~/.git-prompt.sh).
  • Nicolas Zozol
    Nicolas Zozol over 9 years
    oh-my-zsh is very intrusive for only this git benefit