Last active
January 15, 2018 08:47
-
-
Save nbkhope/3b6e88d4ff8ea729450f6c0af80009e2 to your computer and use it in GitHub Desktop.
Current Git Branch Name in Bash Prompt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 $ | |
PS1="...\$(getGitBranch)..." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment