Prepend current git branch in terminal

You can add the following code to you .bashrc file:

parse_git_branch() {
  git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
PS1="${debian_chroot:+($debian_chroot)}\u@\h:\w\$(parse_git_branch) $ "

You can move around these component parts to configure to your tastes, for example to prepend $(parse_git_branch) and not show the user@computer part I used:

PS1="\$(parse_git_branch)${debian_chroot:+($debian_chroot)}\w$ "

Which displays:

(master)~/my_projects/project_x$ 

See also: What is this PS1 variable doing in .bash_profile file?