So, I want to add git to my custom prompt. What I want it to do is:

  1. Show the name of the branch
  2. Change color of the name of the branch if there are uncommitted changes inside the repo

I know there are themes who already do this, but I haven't figured out to do it myself. And, I'd prefer to not use oh-my-zsh, just because I want my setup to be clean and as lightweight as it can be and I don't need all of its components

1 Answer 1


There are lots of guides and snippets around the web, primarily for Bash, but also for Zsh. For example this guide that uses the following code:

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

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

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

It relies on vcs_info from Zsh to give you information on the branch.

By doing a web search for "git prompt zsh" you'll find more. See also this question or this one or a more generic guide on vcs_info.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.