Show your current git branch in your Bash terminal prompt

I recently found this little nugget and had to share. This setup allows you to see your current git branch in your terminal prompt.
To set this up:

  • Download and save it where you please. I saved it as ~/
  • Add the following to your ~/.bash_profile

source ~/
PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ '

  • Enter the following in your terminal session: $ source ~/.bash_profile

Your prompt will look like the following example when in a git repo: [user@host current-folder (git-branch)]. You can customize the prompt configuration as you wish.


Blog Category: