Skip to content

Instantly share code, notes, and snippets.

@z448
Created June 14, 2016 08:33
Show Gist options
  • Save z448/22ded8ac3a028a78f2f77af5624d0986 to your computer and use it in GitHub Desktop.
Save z448/22ded8ac3a028a78f2f77af5624d0986 to your computer and use it in GitHub Desktop.
display current git branch in terminal prompt
#!/bin/bash
# to display current git branch in terminal prompt on start of session add this to your ~/.bashrc file
# ex.: if you are in folder which is git repository switched to master branch your prompt will look like
# /home/joe [master] _
#
# source http://perltricks.com/article/displaying-the-git-branch-in-the-terminal-prompt-with-perl/
function current_git_branch {
git branch 2> /dev/null | perl -ne 'print " [$_]" if s/^\*\s+// && chomp'
}
PS1="\w\$(current_git_branch) "
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment