Ubuntu – Git Branch in ZSH Prompt

command linegitzsh

When working on a git repository with multiple branches, how do I modify my zsh prompt to include my current active branch?

Best Answer

Use the vcs_info function in the zsh user contributions (included in the zsh package). Quick start:

autoload -Uz vcs_info
precmd () { vcs_info }
setopt prompt_subst
PS1="\$vcs_info_msg_0_$PS1"

It's likely that you'll want to make the output prettier. Since that's matter of personal taste, I refer you to the examples in the documentation.