Beginner’s Guide: How to Manage Multiple GitHub Accounts on Mac

Shravan Meena
4 min readMay 28, 2023

--

Introduction:

Managing multiple GitHub accounts on your Mac can be a valuable skill, especially if you work on different projects or contribute to various open-source communities. However, navigating between accounts can seem daunting for beginners. In this step-by-step guide, we’ll walk you through the process of setting up and managing multiple GitHub accounts on your Mac, making it beginner-friendly with clear examples.

Step 1: Set up SSH keys

  1. Open Terminal on your Mac. You can find it by going to “Applications” > “Utilities” > “Terminal”.
  2. To check if you already have SSH keys, type the following command and press Enter:
ls -al ~/.ssh

3. If you see files named id_rsa and id_rsa.pub in the output, you already have SSH keys, and you can skip to Step 2. Otherwise, generate a new SSH key by running this command and pressing Enter:.

ssh-keygen -t rsa -C "your_email@example.com"

Note: Replace "your_email@example.com" with the email address associated with your GitHub account.

4. You'll be prompted to choose a file path to save the SSH key. Press Enter to accept the default path (or change the file name `/Users/{your_username}/.ssh/custom_name`).

5. You'll also be asked to enter a passphrase. It's optional but recommended for added security.

6. Repeat steps 2-5 if you want to set up SSH keys for your other GitHub accounts.

VIDEO TUTS:

Step 2: Add SSH keys to GitHub

Copy the SSH key to your clipboard by running this command and pressing Enter:

pbcopy < ~/.ssh/id_rsa.pub
  1. Go to the GitHub website (https://github.com) and log in to the account for which you want to add the SSH key.
  2. Click on your profile picture in the top-right corner and select “Settings” from the dropdown menu.
  3. In the left sidebar, click on “SSH and GPG keys”.
  4. Click on the green “New SSH key” button.
  5. Give the key a descriptive title (e.g., “Mac SSH Key”) and paste the key into the “Key” field.
  6. Click on the green “Add SSH key” button.
  7. Repeat steps 2–7 to add SSH keys for your other GitHub accounts.

Step 3: Create an SSH configuration file

  1. Open Terminal on your Mac.
  2. Navigate to the SSH directory by running this command and pressing Enter:
cd ~/.ssh

3. Create or edit the SSH configuration file by running this command and pressing Enter:

touch config
open -e config

4. In the text editor that opens, add the following lines for each of your GitHub accounts:

# Account 1
Host github.com-personal
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa

# Account 2
Host github.com-professional
HostName github.com
User git
IdentityFile ~/.ssh/other_key

Note: Replace personal and professional with unique identifiers for your GitHub accounts. Replace ~/.ssh/other_key with the file path to the SSH key of the respective account.

5. Save and close the configuration file.

Save key identities in local machine

First, we have to remove any existing identities by running the following command.

cd ~
ssh-add -D

After delete, check if the newly added keys were saved successfully by running the following command.

ssh-add -l

Now you have to authenticate the keys with GitHub by running following commands.

ssh -T github.com-personal
ssh -T github.com-professional

Now, we’re almost done!

Step 4:

For brand new Repository

  1. Open Terminal on your Mac.
  2. Change to the directory where you want to clone the repository. For example:
cd Documents/Projects

3. Clone a repository using the following command and press Enter:

git clone git@github.com-personal:username/repo.git

Note: Replace personal with the identifier for the GitHub account you want to use, username with your GitHub username, and repo with the name of the repository.

4. Repeat Step 4 for cloning repositories using your other GitHub accounts.

For Existing Repository

  1. First check remote of existing
git remote -v

2. Most probably it will list you remote in format

git@github.com:{repo-owner-name}/{repo-name}.git

3. We have to modify this remote origin to the following format

git remote set-url origin git@github.com-{identifier}/{repo-owner-name}/{repo-name}.git

Note: It should look like this git@github.com-personal:username/repo.git

Step 5: Configure local Git settings

  1. Open Terminal on your Mac.
  2. Change to the directory of the cloned repository. For example:
cd Documents/Projects/repo

3. Configure your local Git settings by running the following commands and pressing Enter after each one:

git config user.name "Your Name"
git config user.email "your_email@example.com"

Note: Replace "Your Name" and "your_email@example.com" with your desired name and email for the current GitHub account.

4. Repeat steps 2–3 for each cloned repository and GitHub account.

Step 6: Switch between GitHub accounts

  1. Open Terminal on your Mac.
  2. Change to the directory of the cloned repository for the account you want to use.
  3. Use the following command to switch to the desired GitHub account and press Enter:
git config user.name "Your Name"
git config user.email "your_email@example.com"

Note: Replace "Your Name" and "your_email@example.com" with the name and email associated with the GitHub account you want to use.

4. Repeat steps 2–3 whenever you need to switch between GitHub accounts.

Conclusion:

Congratulations! You have successfully learned how to manage multiple GitHub accounts on your Mac. By following these beginner-friendly steps and examples, you can seamlessly work on different projects or contribute to various open-source communities without the hassle of constantly switching accounts. Remember to switch to the appropriate account configuration when working with a specific repository to ensure correct authentication and commit attribution.

Comprehensive Guide: How to Delete All Existing GitHub Accounts on Mac

https://shravanmeena.medium.com/comprehensive-guide-how-to-delete-all-existing-github-accounts-on-mac-d2f6f118443a

--

--

Shravan Meena
Shravan Meena

Written by Shravan Meena

Writing code is my passion. I firmly believe in the transformative and enhancing power of programming, and how it can improve the lives of those around world.

Responses (2)