Skip to content
Home » Display current Git Branch name in Terminal Prompt in Mac

Display current Git Branch name in Terminal Prompt in Mac

It’s difficult to know the name of the current active GIT branch in the terminal so let’s see how to do configuration to show active Git Branch name in Terminal.
  1. Run below command in terminal to open the file.
    sudo vim ~/.bash_profile
  2. Add below code and save the file.
    # Display current Git branch in terminal prompt.
    parse_git_branch() {
    git branch 2> /dev/null | sed -e ‘/^[^*]/d’ -e ‘s/* (.*)/ (1)/’
    }
    export PS1=”u@h W[33[32m]$(parse_git_branch)[33[00m] $ “

Now access the folder where git repository is present to see that the current active git branch will display in terminal prompt.

Tags:

Leave a Reply

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

0 Shares
Tweet
Pin
Share
Share
Share