Switch between multiple local Git accounts on MacOS with ZSH
Now, I have two GitHub Account on my macbook.
One of the accounts is my work account and the other is my personal account, I will write some code of my own after get off work or when i free.
About Github SSH refer to this document: Github - Connect with SSH.
Now you have created two github ssh keys.
SHH config
for macos add the config file into .ssh/, now the .ssh/ florder tree like this:
1 | ~/.ssh |
and add the settings into config:
1 | Host account_1 |
ZSH alias
add the alias into .zshrc
1 | alias gu-account-1="ssh-add -d ~/.ssh/account_1 && ssh-add ~/.ssh/account_1 && ssh -T git@github.com" |
gu-account-1 => git user account-1 🤣
Or you can freely name it according to your habits, it is all possible.
Then we can easily switch the current github account:

I hope my experience can help you and make you happier writing code.
- Post title:Switch between multiple local Git accounts on MacOS with ZSH
- Post author:Varsion
- Create time:2022-05-18 11:33:51
- Post link:https://blog.varsion.cn/post/46e8ee7c.html
- Copyright Notice:All articles in this blog are licensed under BY-NC-SA unless stating additionally.
Comments