How to show git branch name in Terminal Ubuntu

Time needed: 2 minutes

In this Article will learn how to show git branch name with color in terminal (ubuntu)

  1. Open bashrc file

    Firstly open bashrc file by below cmd.
    gedit ~/.bashrc

  2. Comment old color prompt

    In ~/.bashrc file, you will find a code starting with if[“$color_prompt = yes”] and end’s with fi, just comment this like as shown in below screenshot for reference.ubuntu git bashrc edit

  3. Add below line of code

    parse_git_branch() {
        git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
       if [ "$color_prompt" = yes ]; then
        PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[01;31m\]$(parse_git_branch)\[\033[00m\]\$ '
        PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w$(parse_git_branch)\$ '

    Reference Screenshot
    show git branch name on terminal

  4. Final done

    Here is how your terminal shows branch name when you are into git repository project folder, In below screenshot as you can see we can easily get to know on which github branch we are working on(No need to keep on checking git branch -a).how to show git branch name in prompt terminal ubuntu