Skip to content

Instantly share code, notes, and snippets.

@afaquejam
Last active August 18, 2019 15:44
Show Gist options
  • Save afaquejam/f41b1cefae005987a7a8 to your computer and use it in GitHub Desktop.
Save afaquejam/f41b1cefae005987a7a8 to your computer and use it in GitHub Desktop.
Bash - Show Git Branch
# .bashrc
# Insert this line above your prompt setting
function parse_git_branch {
git branch --no-color 2>/dev/null | grep \* | sed "s/\* \(.*\)/ (\1)/"
}
# Change your prompt from whatever it is (for example):
PS1='${USER}@${HOST}:${PWD} > '
# To
PS1='${USER}@${HOST}:${PWD}$(parse_git_branch) > '
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment