Skip to main content
Andrea Verlicchi

Making the web faster and more user-friendly

How to integrate git in Mac OS Terminal (shell)

Now that zsh is the default shell on Mac OS terminal, you might want to setup you new Mac or VS Code terminal to have a smart integration with git, something similar to git bash for Windows.

Mac OS X Terminal app | blog-11ty git:(main) * git status | On branch main | Your branch is ahead of 'origin/main' by 1 commit. (use "git push" to publish your local commits) | Changes not staged for commit: | (use "git add ‹file>..." to update what will be committed) | (use "git restore ‹file>..." to discard changes in working directory) | modified: content/blog/how-integrate-git-autocomplete-mac-shell-terminal-bash-zsh/index.md | no changes added to commit (use "git add" and/or "git commit -a")
Mac OS Terminal with git integration

After searching around for a while and finding tools to integrate with bash, I finally found this article that offers an explanation on how to integrate git with zsh in Mac OS Terminal (or shell).

Since zsh ships with a framework for getting information from version control systems, called vcs_info, you can include the branch name in the prompt on the right side, add these lines to your ~/.zshrc file:

autoload -Uz vcs_info
precmd_vcs_info() { vcs_info }
precmd_functions+=( precmd_vcs_info )
setopt prompt_subst
RPROMPT='${vcs_info_msg_0_}'
# PROMPT='${vcs_info_msg_0_}%# '
zstyle ':vcs_info:git:*' formats '%b'

Zsh is powerful enough that there are entire frameworks dedicated to making it better. One of them is called oh-my-zsh. oh-my-zsh’s plugin system comes with powerful git tab-completion, and it has a variety of prompt "themes", many of which display version-control data.

You can install oh-my-zsh running fhe following command:

sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

Enjoy your new zsh terminal integrated with git commands!