Adding the Oh My Zsh git plugin to show branch and status in your prompt
Learn how to enable Oh My Zsh's git plugin, configure its environment variables, and verify that your shell prompt displays branch names and change indicators.
03 Aug 2025, 04:01 UTC

Problem: Your prompt hides git context
You open a terminal inside a Git repository and the prompt shows only the current directory. You would like to see the branch name and a quick sign of staged or unstaged changes without typing git status each time.
Thesis
Enabling Oh My Zsh’s built‑in git plugin and making sure your theme calls its prompt functions adds branch and dirty‑state information to the prompt with only a few milliseconds of startup overhead.
How Oh My Zsh loads plugins
Oh My Zsh stores each plugin as a directory under ~/.oh-my-zsh/plugins. When a new shell starts, it sources oh-my-zsh.sh, which reads the plugins array from ~/.zshrc. Every name listed in that array causes the corresponding plugin’s plugin.zsh file to be sourced, making its functions and completions available in the session.
To activate the git plugin you add the string git to that array. No extra installation steps are required because the plugin ships with Oh My Zsh.
What the git plugin provides
The plugin defines a handful of shell functions, the most useful for prompts being:
git_prompt_info– returns the current branch name (e.g.,(main)) or an empty string if not in a repository.git_prompt_status– returns indicators for staged (+), unstaged (*), untracked (%) and other states.git_prompt_aheadandgit_prompt_behind– show how many commits the local branch is ahead or behind its upstream.
The plugin’s output can be tuned with environment variables that must be set before oh-my-zsh.sh is sourced:
GIT_PROMPT_SHOW_UPSTREAM– when set to1, includes upstream tracking info.GIT_PROMPT_SHOW_DIRTY_STATE– when set to1, shows the*/+dirty markers.GIT_PROMPT_SHOW_UNTRACKED_FILES– when set to1, adds a%for untracked files.
Worked example: enabling and verifying the plugin
- Edit your configuration – open
~/.zshrcin a text editor (you need only your user permissions). Find the line that defines thepluginsarray; it looks like:
# Example line
plugins=(git)
If the line does not already contain git, add it inside the parentheses, separated by spaces. Save the file.
- Set optional environment variables – place the exports before the line that sources
oh-my-zsh.sh:
# Show upstream and dirty state
GIT_PROMPT_SHOW_UPSTREAM=1
GIT_PROMPT_SHOW_DIRTY_STATE=1
source $ZSH/oh-my-zsh.sh
- Reload the shell – start a new terminal window or run
exec zshto apply the changes. - Confirm the plugin is loaded – in the new session execute:
echo ${(j,:,)plugins}
You should see git among the listed plugin names.
- Check the prompt in a repository – change into any directory that is a Git working tree. The prompt should now display something like:
~/project (main) *+
Here (main) is the branch from git_prompt_info, * indicates unstaged changes, and + indicates staged changes (assuming the variables above are set).
- Validate the environment variable effect – temporarily hide the dirty state:
unset GIT_PROMPT_SHOW_DIRTY_STATE
exec zsh
Return to the same repository; the * and + symbols should disappear, confirming the plugin respects the variable.
Trade‑off and limitation
The plugin adds virtually no startup cost because it only sources a few function definitions. However, if your chosen Oh My Zsh theme does not call git_prompt_info (or related functions) in its PROMPT definition, enabling the plugin will produce no visible change, which can be confusing during troubleshooting. Additionally, the plugin assumes the git executable is present in $PATH; on systems where Git is not installed the functions return empty strings and may emit harmless warnings.
Actionable closing
To get branch and status information in your Oh My Zsh prompt:
- Add
gitto thepluginsarray in~/.zshrc. - Optionally set
GIT_PROMPT_SHOW_UPSTREAM,GIT_PROMPT_SHOW_DIRTY_STATE, orGIT_PROMPT_SHOW_UNTRACKED_FILESbefore sourcingoh-my-zsh.sh. - Start a new shell, verify the plugin appears in
$plugins, and look for branch/status symbols in a Git repository. - If nothing appears, check that your theme calls the git prompt functions or temporarily switch to a known‑working theme like
agnoster.
With these steps you gain immediate visual feedback about your repository state without extra commands, and you can adjust the verbosity through simple environment variables.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.