Tuesday, August 29, 2023

Add Git Branch Name to Terminal Prompt

 

GIT


Go to $HOME/.ssh folder edit .bash_profile and add the following entries and run the command-> . .bash_profile

git@yashwanthsn-VirtualBox .ssh $ cat .bash_profile
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^]/d' -e 's/ (.*)/ (\1)/'
}
export PS1="\u@\h \W[\033[32m]\$(parse_git_branch)[\033[00m] $ "

Go to local Git repository directory, and immediately you will see the branch listed at the prompt
Create a branch called test and switch to test branch by issuing following Git command

git checkout -b test


Also list out branches by running git branch command

Git branch


You can switch between the branch using

git checkout <branch-name>