A Zsh prompt that shows the active Git branch makes repository context visible before each command. That context matters before commits, rebases, deployments, and cleanup commands where the wrong branch can change the wrong code.
Zsh includes vcs_info for version-control prompt metadata. It reads the current repository state, writes a formatted result to vcs_info_msg_0_, and can refresh from a precmd hook before each prompt is drawn.
The configuration belongs in the interactive Zsh startup file, usually ~/.zshrc. Back up that file before changing PROMPT, enable prompt substitution so the refreshed variable expands at display time, and place the block after any theme or framework that rewrites the prompt.
Related: How to customize the Zsh prompt with PS1
Related: How to configure Zsh startup files
$ test -f ~/.zshrc && cp ~/.zshrc ~/.zshrc.bak
No output means the backup command found no existing file to copy or copied the file without reporting a message. If ZDOTDIR is set, back up $ZDOTDIR/.zshrc instead.
$ vi ~/.zshrc
If ZDOTDIR is set, edit $ZDOTDIR/.zshrc instead of ~/.zshrc.
autoload -Uz vcs_info add-zsh-hook
zstyle ":vcs_info:git:*" formats "(%b)"
prompt_vcs_info() { vcs_info }
add-zsh-hook precmd prompt_vcs_info
setopt prompt_subst
PROMPT='${vcs_info_msg_0_:+$vcs_info_msg_0_ }%# '
add-zsh-hook attaches the refresh without replacing an existing precmd function. Replace only the PROMPT assignment if the rest of the file already sets colors, host names, or path segments that should stay visible.
$ zsh -n ~/.zshrc
No output means Zsh accepted the file syntax.
$ git init -b main repo Initialized empty Git repository in /home/operator/repo/.git/
$ cd repo
$ zsh -ic 'vcs_info; print -r -- "segment=$vcs_info_msg_0_"' segment=(main)
The check calls vcs_info once because a non-tty command exits before drawing a normal prompt.
The prompt should show (main) before the prompt character. If it does not change, check whether a later theme or prompt framework is replacing PROMPT after the vcs_info block runs.