Work around slowness of oh-my-zsh Git plugins on large repositories

I spend more than half my work life using a command line terminal. I recently switched from the BASH shell to ZSH via oh-my-zsh.

I love oh-my-zsh!!

However, I have to work with a relatively large Git repository. This means, once navigate into this Git repo via the ZSH command line, each time the prompt is painted, there is a painful 2-3 sec wait. This doesn’t sound like much, but it really gets in the way of the flow of work when it continuously happens over several hours of work.

I am using the sunrise oh-my-zsh theme and the zsh prompt with this theme displays both the current Git branch and the dirty state of the repo. I had a strong inkling the latter dirty state computation was the culprit causing the slowness for me.

Looking into the ~/.oh-my-zsh/themes/sunrise.zsh.theme file, I found the custom_git_function() which is responsible for constructing the command prompt. The actual line of interest looks like:

echo "$ZSH_THEME_GIT_PROMPT_PREFIX${ref#refs/heads/}$(parse_git_dirty)$(git_prompt_ahead)$(custom_git_prompt_status)$ZSH_THEME_GIT_PROMPT_SUFFIX"

The parse_git_dirty, git_prompt_ahead and custom_git_prompt_status sections seemed like the problem. For me, all I want to know is the current branch. I really don’t care about these status flags.

I dropped these three status sections, resulting in a line like:


I saved this change to sunrise.zsh.theme file and re-launched my ZSH command prompt.

Voila! Speedy painting of the prompt in my large Git repo.

I am sure there is a cleaner way to override the ZSH prompts specified in an oh-my-zsh theme. If anyone out there knows or can point me to the documentation for this, I’d really appreciate it.


2 thoughts on “Work around slowness of oh-my-zsh Git plugins on large repositories

  1. 6 years later and this is still the best solution. I had to change my theme to sunrise from the default though.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s