Notes

Add git info to Bash prompt

Edit on GitHub

Git & Github

On my MacBook i have ZShell and an amazing custom prompt. This is more for my remote Ubuntu servers where i have hosted code and would like the git info in the prompt

1# find your git version and download the files `git-completion.bash` and `git-prompt.sh`
2GIT_VERSION=`git version | sed 's/git version //'`
3
4wget -O ~/git-prompt.sh https://raw.githubusercontent.com/git/git/v${GIT_VERSION}/contrib/completion/git-prompt.sh
5
6# one liner
7# wget -O ~/git-prompt.sh https://raw.githubusercontent.com/git/git/v`git version | sed 's/git version //'`/contrib/completion/git-prompt.sh

Add the following to the end of your ~/.bashrc

1# Git prompt
2# https://git-scm.com/book/en/v2/Appendix-A:-Git-in-Other-Environments-Git-in-Bash
3. ~/git-prompt.sh
4export GIT_PS1_SHOWDIRTYSTATE=1
5#export PS1='\w$(__git_ps1 " (%s)")\$ '
6#export PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u\[\033[00m\]@\[\033[01;32m\]\h\[\033[00m\] \[\033[01;34m\]\w\[\033[00m\] $(__git_ps1 " (%s)") \$ '
7export PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u\[\033[00m\]@\[\033[01;32m\]\h\[\033[00m\] \[\033[01;34m\]\w\[\033[00m\] \$ $(__git_ps1 "(%s)") '

And then source ~/.bashrc for the changes to take effect