Add Git branch information to your ZSH 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
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.
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:
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:
4. Reload to see the changes
Save, and reload your zshrc config file
Admire your handiwork!
Go further
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.