Skip to content

Instantly share code, notes, and snippets.

@scaint
Created June 16, 2013 09:34
Show Gist options
  • Select an option

  • Save scaint/5791534 to your computer and use it in GitHub Desktop.

Select an option

Save scaint/5791534 to your computer and use it in GitHub Desktop.
Show the current Git branch in Bash prompt
#Based on https://github.com/jimeh/git-aware-prompt
find_git_branch() {
local branch
if branch=$(git rev-parse --abbrev-ref HEAD 2> /dev/null); then
if [[ "$branch" == "HEAD" ]]; then
branch='detached*'
fi
git_branch=" ($branch)"
else
git_branch=""
fi
}
PROMPT_COMMAND="find_git_branch; $PROMPT_COMMAND"
export PS1="\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\u@\h:\w\e[0;36m\$git_branch\e[0m\$ "
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment