Add Git Branch Name to Bash Prompt
-
Add the following lines to your
~/.bashrcfile:parse_git_branch() { git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/' } export PS1="\u@\h \[\033[32m\]\w\[\033[33m\]\$(parse_git_branch)\[\033[00m\] $ "Where:
-
\u@\h \[\033[32m\]displays the user, host name, and its color. -
\w\[\033[33m\]shows the current working directory and its color. -
\$(parse_git_branch)\[\033[00m\]displays the git branch name and its color.
Typically, I only display the current working directory and the git branch name without showing the user and hostname.
-
-
Run the command
source ~/.bashrcto apply the changes.
Source:
Coderwall
Enjoy Reading This Article?
Here are some more articles you might like to read next: