Last Updated: February 25, 2016
· jurasarts
1604713 740033406014298 224042007 n

How show git branch in terminal (with colors)

If you want your terminal to be more bright, you can use this code.

1. Open terminal

2. gedit ~/.bashrc

3. Add this to the bottom of the file:

function color_my_prompt {
    local __user_and_host="\[\033[01;32m\]\u@\h"
    local __cur_location="\[\033[01;34m\]\w"
    local __git_branch_color="\[\033[31m\]"
    local __git_branch='`git branch 2> /dev/null | grep -e ^* | sed -E  s/^\\\\\*\ \(.+\)$/\(\\\\\1\)\ /`'
    local __prompt_tail="\n\[\033[35m\]$"
    local __last_color="\[\033[00m\]"
    export PS1="$__user_and_host $__cur_location $__git_branch_color$__git_branch$__prompt_tail$__last_color "

This will also move carret to the new line, so writing new commands would be more easier.

Say Thanks