Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Current Git Branch Name in Bash Prompt
# Display the current branch name in your bash prompt
# If current directory is not under a git repository, displays an empty string
# Add this function to your .bashrc (or .bash_profile in macOS)
getGitBranch() {
[ -d ".git" ] && git branch | grep \* | cut -d" " -f2
# Include this in your PS1 definition
# Don't forget to include the backslash before $
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.