Add Git to your terminal prompt

Add Git to your terminal prompt

Add Git to your terminal prompt

By Jack Lot Raghav

Jack Lot Raghav

/

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.


By Jack Lot Raghav

Jack Lot Raghav

I attended the University of Maryland where I graduated with a bachelor's degree in Computer Science. Since then, I’ve gathered experience in the tech industry, both as a software engineer and people manager. My longest stint was 7 years at Amazon where I… read more.

Understand Git in Hours Not Years.

LearnGit.io is a premium learning platform. 40+ video lessons with unique animated visualizations, high-quality search, and more.

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