Assume you want to use your personal Github account on your work laptop, and wanted to commit to your personal account without breaking your work repository configuration. In this tutorial I will show you how to easily manage multiple Github/Bitbucket accounts on MacOS without conflict each other.
To achieve our goal we need to tell Github/Bitbucket Git's engine that we have multiple account in one computer.
So bare with me to achieve our goal.
- Go to SSH directory
$ cd ~/.ssh
- Create a new SSH key
ssh-keygen -t rsa -b 4096 -C <firstname.lastname@example.org?More on Github
- This is very strait forward, just follow the Adding a new SSH key to your GitHub account
To connection to multiple remote server through the SSH we can use the SSH
config file. I'm not going to explain what is
config file in this post, but if you like to learn more about that here "Using the SSH Config File" is a cool article that I found for you. Ok less talk do more!
- Create a config file
$ cd ~/.ssh && touch config
- Add your SSH configuration to
Here is the syntax that you need to understand.
# Host is the remote server Host hostname1 SSH_OPTION value SSH_OPTION value
In our case we want to use multiple Github/Bitbucket accounts, so it will be
# Your Github account Host github.com-<jeffshomali> User git HostName github.com IdentityFile ~/.ssh/<jeff_personal> IdentitiesOnly yes
Just replace the
<> with your information.
Go to your Github account and clone of the repository.
- Open the repo in your code editor and make sure the Origin
pushurls are set with
$ git remote -vif not set that up with
$ git remote add origin https://github.com/user/repo.git
To prevent the conflict between your personal repo and your work repos you need to add your information to each repo by add the username and email to local repo.
- Open your Git config file with
$ code .git/configor
$ git config --local -e.
- Add your username and email
[user] name = your_github_username email = email@example.com
- Confirm your information has been saved and present in config file by
$ git config --local -land you should see your Github/Bitbucket