Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show git branch and status in Mac Bash [duplicate]

Tags:

git

bash

macos

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

like image 714
Dozer Avatar asked May 14 '13 06:05

Dozer


People also ask

How do I show the git branch with Colours in bash prompt?

the command prompt will start with username@host and a space ( \u@\h ), in default terminal color (normally, white text on black background). Then comes \[\e[32m\]\w — current working directory ( \w ) in green ( [32m ) color, and a space.

Where is __ git_ps1 defined?

It's /etc/git-prompt.sh that defines the __git_ps1 function (Line #273 in my version) is defined. You'll notice that the __git_ps1 function pulls in several other functions defined in /etc/git-prompt.sh .


1 Answers

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.

like image 185
djromero Avatar answered Oct 06 '22 01:10

djromero