Skip to content

Instantly share code, notes, and snippets.

@kirsle kirsle/.bashrc
Created Jan 17, 2017

Embed
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)"
fi
}
# 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
You can’t perform that action at this time.