Branch Name in terminal
suggest changeWhat is PS1
PS1 denotes Prompt String 1. It is one of the prompts available in a Linux/UNIX shell. When you open your terminal, it displays the value of PS1. To add the branch name to the bash prompt, set PS1 in ~/.bash_profile.
Display git branch name
Add the following lines to your ~/.bash_profile:
git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
export PS1="\u@\h \[\033[32m\]\w\[\033[33m\]\$(git_branch)\[\033[00m\] $ "
This git_branch function prints the current branch name. After you save the file, open a Git repository in the terminal and the prompt shows the branch name. The git branch pipeline does not report a name while HEAD is detached.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents