Skip to content

Instantly share code, notes, and snippets.

@ragar90
Last active October 23, 2023 19:29
Show Gist options
  • Save ragar90/5c559ad02d5de0e4786db4957ef1aa0a to your computer and use it in GitHub Desktop.
Save ragar90/5c559ad02d5de0e4786db4957ef1aa0a to your computer and use it in GitHub Desktop.
Display your current branch on your terminal
# Steps to install it
# 1. Open .bashrc with nano ~/.bashrc
# 2. Scroll to the bottom of the file
# 3. Copy and paste the code below
# 4. Reload your terminal just by closing it and reopen it or by calling source ~/.bashrc
# 5. Move to any git repo and ensure you have a prompt like the following dev0@dev0-Precision-7770 learning-hub (staging)$
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
export PS1="\u@\h \[\e[32m\]\W \[\e[91m\]\$(parse_git_branch)\[\e[00m\]$ "
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment