tutorials

Add Git to your terminal prompt

Add Git to your terminal prompt

Add Git to your terminal prompt

ZSH's vcs_info unlocks some interesting prompt customizations

ZSH's vcs_info unlocks some interesting prompt customizations

By Jack Lot Raghav

Jack Lot Raghav

Founder, LearnGit.io

One of my favorite terminal customizations is adding Git repository/branch information to my prompt. I use ZSH as my default shell, and that’s a good thing here because ZSH ships with a function called vcs_info specifically for grabbing version control information.

1. Open your .zshrc config file

vi
vi
vi

If your config file doesn’t exist, create it first using touch ~/.zshrc

2. Load in the version control system (VCS) info

Add the following lines to your .zshrc config file.

# Load version control information
autoload -Uz vcs_info
precmd() { vcs_info }

# Format the vcs_info_msg_0_ variable
zstyle ':vcs_info:git:*' formats 'on %b'
# Load version control information
autoload -Uz vcs_info
precmd() { vcs_info }

# Format the vcs_info_msg_0_ variable
zstyle ':vcs_info:git:*' formats 'on %b'
# Load version control information
autoload -Uz vcs_info
precmd() { vcs_info }

# Format the vcs_info_msg_0_ variable
zstyle ':vcs_info:git:*' formats 'on %b'

In the snippet above, %b will be replaced by the branch name

3. Add version control info to PROMPT

After loading in VCS info (in step 3 above), use the vcs_info_msg_0_ variable in your PROMPT string:

# Set up the prompt (with git branch name)
setopt PROMPT_SUBST
PROMPT='%n in ${PWD/#$HOME/~} ${vcs_info_msg_0_}
%# '
# Set up the prompt (with git branch name)
setopt PROMPT_SUBST
PROMPT='%n in ${PWD/#$HOME/~} ${vcs_info_msg_0_}
%# '
# Set up the prompt (with git branch name)
setopt PROMPT_SUBST
PROMPT='%n in ${PWD/#$HOME/~} ${vcs_info_msg_0_}
%# '


Optional: If you want that branch info to display aligned to the right, remove the ${vcs_info_msg_0_} line from your PROMPT and add an RPROMPT line to your config file instead:

RPROMPT
RPROMPT
RPROMPT

4. Reload to see the changes

Save, and reload your zshrc config file

source
source
source

Admire your handiwork!


In this screenshot I set RPROMPT=\$vcs_info_msg_0_ in my .zshrc config so that branch information is right-aligned

Go further with vcs_info and nerdfonts

That’s it. If you want to go further, vcs_info provides other version control information such as staged/unstaged files, stash information etc. Check out this fantastic article by Arjan van der Gaag to see what else you can do.

To add iconography to your prompt — like how in this article's cover photo I added the Git branch icon — check out nerdfonts.


Make Git Finally Click.

Stop guessing what Git is doing. Confidently instruct AI agents, and fix mistakes instead of fearing them.

Mental models beat memorization

Stop guessing what Git is doing. Confidently instruct AI agents, and fix mistakes instead of fearing them.

Mental models beat memorization

Stop guessing what Git is doing, and start building real Git confidence.

Support

Need help? Email support@learngit.io

© 2026 LEARNGIT.IO

Support

Need help? Email support@learngit.io

© 2026 LEARNGIT.IO

Support

Need help? Email support@learngit.io

© 2026 LEARNGIT.IO