Skip to content

Instantly share code, notes, and snippets.



Created Jan 17, 2017
What would you like to do?
Show current git branch name in Bash prompt
# Function that prints the branch name.
git_branch() {
branch=`git branch 2> /dev/null | sed -e '/^[^*]/d' | perl -pe 's/^\*\s+//g'`
if [ "$branch" != '' ]; then
echo -n " ($branch)"
# Integrate it into your $PS1 prompt.
# Would look like: [user@localhost myapp (master)]$
export PS1="[\u@\h \W\$(git_branch)]\$ "
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment