Colorizing Your Git Experience

Here we will make two small changes to your shell to work with Git. These changes will: 1) Make your command prompt show you the current branch name, and 2) show Git diffs in color.

You’ll want to add this code to the ~/.zshrc file on your machine.

# FOR SETTING GIT TO SHOW DIFFS IN COLOR (RED/GREEN)
parse_git_branch() {
git branch 2> /dev/null | sed -n -e 's/^* (.*)/[\1]/p'
}
COLOR_DEF='%f'
COLOR_USR='%F{243}'
COLOR_DIR='%F{197}'
COLOR_GIT='%F{39}'
NEWLINE=$'\n'
setopt PROMPT_SUBST
export PROMPT='${COLOR_USR}%n@%M ${COLOR_DIR}%d ${COLOR_GIT}$(parse_git_branch)${COLOR_DEF}${NEWLINE}%% '

This tweak will add the full path and also the current git branch to your terminal prompt.