Skip to content

Instantly share code, notes, and snippets.

@mjj2000
Last active December 19, 2015 00:29
Show Gist options
  • Save mjj2000/5869097 to your computer and use it in GitHub Desktop.
Save mjj2000/5869097 to your computer and use it in GitHub Desktop.
Show current git branch and state in command line prompt
1. Download git-prompt.sh and saved as hidden file .git-prompt.sh
curl -L https://raw.github.com/git/git/master/contrib/completion/git-prompt.sh -o ~/.git-prompt.sh
2. apply git-prompt and insert branch variable $(__git_ps1) in prompt in your shell configuration file (ex: ~/.bashrc)
# colors
MAGENTA="\[\033[0;35m\]"
YELLOW="\[\033[0;33m\]"
BLUE="\[\033[34m\]"
LIGHT_GRAY="\[\033[0;37m\]"
CYAN="\[\033[0;36m\]"
GREEN="\[\033[0;32m\]"
COLOR_OFF="\[\033[0m\]"

# set customized prompt
source ~/.git-prompt.sh
GIT_PS1_SHOWDIRTYSTATE=true
export PS1='\u@\h \w'$YELLOW'$(__git_ps1 "(%s)")'$COLOR_OFF' \\$ '
export SUDO_PS1="[\u@\h \w]\\$ " # PS1 only for sudo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment