This content originally appeared on DEV Community and was authored by Jeff Shomali
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.
Create a new SSH key
- Go to SSH directory
$ cd ~/.ssh
- Create a new SSH key
ssh-keygen -t rsa -b 4096 -C <your_email@example.com?
More on Github
Register created SSH key to Github
- This is very strait forward, just follow the Adding a new SSH key to your GitHub account
Create SSH Config
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
config
.
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.
Clone your repository.
Go to your Github account and clone of the repository.
- Open the repo in your code editor and make sure the Origin
fetch
andpush
urls are set with -
$ git remote -v
if not set that up with$ git remote add origin https://github.com/user/repo.git
Add your Github username and email to every repo locally.
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/config
or$ git config --local -e
. - Add your username and email
[user]
name = your_github_username
email = your_github_email@email.com
- Confirm your information has been saved and present in config file by
$ git config --local -l
and you should see your Github/Bitbucketuser.name
anduser.email
.
Done!
This content originally appeared on DEV Community and was authored by Jeff Shomali
Jeff Shomali | Sciencx (2021-11-25T22:27:25+00:00) Integrating MacOS with multiple Github or Bitbucket accounts. Retrieved from https://www.scien.cx/2021/11/25/integrating-macos-with-multiple-github-or-bitbucket-accounts/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.