Skip to content

Instantly share code, notes, and snippets.

@kirsle
Created January 17, 2017 21:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kirsle/9f7eefa8e58517956688a66c711456a6 to your computer and use it in GitHub Desktop.
Save kirsle/9f7eefa8e58517956688a66c711456a6 to your computer and use it in GitHub Desktop.
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