Enable the Git Plugin in Oh My Zsh to Show Branch and Dirty State in Prompt
Learn how to enable Oh My Zsh’s Git plugin so your shell prompt shows the current branch and a dirty‑state indicator.
08 Oct 2026, 05:28 UTC

Desired outcome
After enabling the Git plugin, your shell prompt will display the current branch name when you are inside a Git‑managed directory and will change visually (e.g., add an asterisk or change color) when the working tree has uncommitted changes.
Prerequisites
- Oh My Zsh installed and set as your default shell.
- The
gitexecutable present in your$PATH. - Write permission to edit
~/.zshrc(your user’s home directory).
Procedure
- Open the configuration file in a text editor (e.g.,
nano ~/.zshrcorvim ~/.zshrc). - Locate the line that defines the plugins array; it usually looks like
plugins=(git)orplugins=(…). - Ensure the word
gitappears inside the parentheses. If it is missing, add it, separating it with spaces from other plugins, e.g.,plugins=(git docker). - Save the file and exit the editor.
- Reload the configuration without closing the terminal: run
source ~/.zshrc. Alternatively, start a new terminal session.
Expected checks
- Navigate to any directory that is a Git repository (
cd /path/to/repo). - Observe the prompt: it should show the branch name in parentheses, e.g.,
(main). - Make a change (
echo test > foo.txt) and save it. - The prompt should update to indicate a dirty state; the exact visual cue depends on your theme (many themes add an asterisk
*or change the branch color). - Run
git statusto confirm the working tree is indeed dirty; the prompt should reflect the same state.
Recovery options
If the prompt behaves unexpectedly or you wish to disable the Git plugin:
- Edit
~/.zshrcagain. - Either remove
gitfrom the plugins array or comment out the entire line (# plugins=(git)). - Save the file and run
source ~/.zshrcor open a new terminal. - The prompt will revert to its previous behavior.
Limitations and practical verification
The Git plugin only affects the prompt when Oh My Zsh’s theme uses the git_prompt_info function (most bundled themes do). If you have a custom PROMPT variable or a theme that does not call this function, the branch indicator may not appear. To verify that your theme supports it, run echo $ZSH_THEME and consult the theme’s source file in $ZSH/themes/ for a reference to git_prompt_info. If the function is missing, consider switching to a theme that includes it (e.g., agnoster, robbyrussell) or adding the function manually to your custom theme.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.