Skip to content

Instantly share code, notes, and snippets.

@amdelamar
Created January 22, 2022 21:42
Show Gist options
  • Save amdelamar/7c06eb52c70e702ba378ad9e7f7e2e2f to your computer and use it in GitHub Desktop.
Save amdelamar/7c06eb52c70e702ba378ad9e7f7e2e2f to your computer and use it in GitHub Desktop.
Add Git Branch Name to Terminal Prompt (Linux/Mac)

Add Git Branch Name to Terminal Prompt (Linux/Mac)

screenshot

Open ~/.bashrc in your favorite editor and add the following content to the bottom.

# Git branch in prompt.
parse_git_branch() {
  git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}

# Linux
export PS1="\e[1m\e[32m\u@\h\e[0m\e[0m:\e[1m\e[34m\w\e[0m\e[1;33m\$(parse_git_branch)\e[0m\$ "

# MacOS
export PSQ="\[\033[34m\]\\u@\h\[\033[00m\]:\W\[\033[32m\]\$(parse_git_branch)\[\033[00m\]$ "
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment