Skip to content

Instantly share code, notes, and snippets.

@nbkhope
Last active January 15, 2018 08:47
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 nbkhope/3b6e88d4ff8ea729450f6c0af80009e2 to your computer and use it in GitHub Desktop.
Save nbkhope/3b6e88d4ff8ea729450f6c0af80009e2 to your computer and use it in GitHub Desktop.
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 $
PS1="...\$(getGitBranch)..."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment