# Add Git Branch Name to Terminal Prompt (zsh) ## Updated for MacOS with zsh * Catalina * Big Sur * Monterey * Ventura * Sonoma screenshot ### Install Open `~/.zshrc` in your favorite editor and add the following content to the bottom. ```sh function 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}' setopt PROMPT_SUBST export PROMPT='${COLOR_USR}%n ${COLOR_DIR}%~ ${COLOR_GIT}$(parse_git_branch)${COLOR_DEF} $ ' ``` ### Reload and apply adjustments To reload and apply adjustments to the formatting use `source ~/.zshrc` in the zsh shell. ### Credits * Thank you benP2ER for the useful additions in [his comment](https://gist.github.com/reinvanoyen/05bcfe95ca9cb5041a4eafd29309ff29?permalink_comment_id=4117181#gistcomment-4117181) * Original gist by Jose Quintana: [Add Git Branch Name to Terminal Prompt (Linux/Mac) ](https://gist.github.com/joseluisq/1e96c54fa4e1e5647940)