You have to modify the PS1
variable. PS1
is the primary prompt string, read more here. You should find it defined in either /etc/bashrc
or ~/.bashrc
. Inside this file, create a new function that returns the current branch name
get_branch() {
git branch 2> /dev/null | sed -e "/^[^*]/d" -e "s/* \(.*\)/\1/"
}
then simply append $(get_branch)
to your PS1
string.