HostOnNet Blog

Show Git Branch in Command Prompt

Looking for Linux Server Admin or WordPress Expert? We can help.

To show current active git branch in command prompt in linux terminal, edit ~/.bashrc

vi ~/.bashrc

Add following

show_git_branch() {
    git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}

PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]$(show_git_branch)\$ '

Posted in Git

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.