Last Updated: February 25, 2016
·
581
· rashivkp

Append git-branch name in command line

if you are using your command line as login shell , you have to edit your ~/.bash_profile file, else edit ~/.bashrc , and add following lines

parse_git_branch() {
          git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
      }
PS1="\[\033[36m\]\u${debian_chroot:+($debian_chroot)}\w\[\033[33m\]\$(parse_git_branch)\[\033[00m\]\$(git config user.initials)$\[\033[00m\] " 

Demo:

Picture

if you are editing ~./.bash_profile file you have to add these lines before those..

if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then
      debian_chroot=$(cat /etc/debian_chroot)
fi

prepend-current-git-branch-in-terminal