Managing Multiple Github Accounts

From Setting Up SSH Keys To Determining Which Account You’ll Push To When Adding Repos From Your Local Environment

Osha Groetz
6 min readJan 24, 2021

I recently was working on my first project for a client. Pausing for a quick second to say WOOHOO, I’m very excited for my first real project! I was fortunate that when I started bootcamp, we had an instructor help us quickly walk through the process of setting up our local environments, connecting our Github accounts so that all of our labs and lessons directly connected and made pull requests from our accounts, set up our SSH keys, all of it. Admittedly, at the time, I had no idea what we were actually doing, I merely followed each step afraid that I would miss any of the steps he was having us take, but there was no deep understanding of why or how to recreate the process. When I began building my clients application from scratch, I knew I would eventually need to make sure to duplicate the finished repos in their own business repository. I wouldn’t be their developer forever and they should have their own full, private access to their code. All of the eventually hosted sites would need to be connected to these repos specifically.

In the last phases of finishing the job, I set up every single account that the apps (there were 2: backend and frontend) used so that they were my client’s personal accounts. Github proved to be one of the more complicated, because as I mentioned: I already had my local environment set up to work perfectly with my account, but I needed to understand how to set my environment up for when I was working on other peoples accounts and repos. This blog will walk you through everything from connecting with Github with SSH (used to established a password protected secure connection between your computer and Github) to setting up your apps when you need to push them to your clients Github repos.

If you have not done so, please visit https://github.com/ to signup for your second account. Our very first, important step will be be to set up an SSH key for this new account. Documentation on why cloning with SSH over HTTPs can be found here and setting up the SSH documentation can be found here.

Before we set up the SSH key in our Github, we’ll need to generate this in our local machines, terminal. Type in the command cd ~/.ssh Next, run ssh-keygen -t rsa -b 4096 -C "your_email@example.com"NThe terminal will prompt you to ‘Enter file in which to save the key…’ , below you can see I chose id_rsa_l….od, this can be whatever name you’d like, as long as the value begins with ‘id_rsa_’. When prompted to enter passphrase, just leave empty and hit return, same for ‘Enter same passphrase again”. You will be given the id, the public key and the key fingerprint.

From here, type in the command line ls to see a list of the files that are in this directory. That file that you just set up will be in the list along with a .pub version of the same file. You will need to see the contents of the .pub file (the SSH key is what is contained in the file) by running command:cat “file_name".pub Your terminal will give you a very long value that begins with ‘ssh-rsa’ and ends with your specified email.

This value is what we will need to carry over to our Github account. Let’s navigate to the Github site, and click on your picture (top right hand corner). From the dropdown, select ‘Settings’. Then, select the ‘SSH and GPG keys’ and then ‘New SSH key’.

In the next screen, in the ‘Title’ field, it’s been recommended to me that you put which device this SSH has been generated from. You’ll add your given SSH key from the device into the ‘Key’ field without quotes. Then click the green button ‘Add SSH key’.

Github will save the key and bring you to a screen that looks like this to confirm that all has been saved:

We need to do a few more things in our local environment before we set up the repo. Navigate back to your terminal and follow the command flow: touch config, ls ,nano config

The config file will open directly in the terminal (hence the nano part of the command). In here you will need to setup hosting info for BOTH Github accounts. Below, you will notice that my original id_rsa file is the name of the SSH file containing my personal Github SSH key. The second account will be set up in the exact manner, using the 2nd Github username on the ‘1st’ and ‘2nd’ lines of the config, and the ssh file (not the .pub) that contains the SSH key of the 2nd account.

To exit out of this screen type ‘control — x’ and when prompted, type ‘y’ for yes to save, then hit ‘return’ to get out of this screen asking ‘File Name To Write: config’.

In my instance, I built the entire application and originally set up the repository in my own github account. I needed this entire repo to be set up in my second account, and to do so followed these steps:

While logged in to the second account, go to the Github page of the first account. Upper right-hand corner click ‘Fork’. Github will ask where you’d like to fork the repo, select the 2nd account, where you are currently logged-in. When the repo is done forking, you will notice you are back in your account and a branch of the repo now lives in this second account. Now, click the green ‘Code’ button on right-hand side. Making sure to choose the tab ‘SSH’, copy the SSH code, or click the clipboard to copy it automatically.

Back in the local environment terminal, ‘cd’ into your desired directory that you’d like to clone the repo, and then the next commands will be: git clone <the copied repo SSH from Github>, cd into the cloned file, then git config --local -e

This command will directly open up this particular apps config file in your text editor(for me: VS Code). It’s up to you to make sure the [remote “origin”] url field matches your SSH that you copied from Github and that all other lines match the picture below. It’s VERY important that the url Github account matches the 2nd account you set up. You’ll need to add the [user] field; the name will be your Github name and the email will match your email associated with the Github account.

Going back into your terminal, to open the entire file of the application: code .From the command line inside of your text editor, let’s make sure everything is connected properly from your local repo to your second Github account. Follow these commands: git add ., git commit -m “testing commits", git push Go to your Github account and check the commits to make sure this recent commit has logged in this remote repository.

Other resources used for this blog:

  1. https://gist.github.com/Jonalogy/54091c98946cfe4f8cdab2bea79430f9
  2. https://www.youtube.com/watch?v=lLgWWtOk7gk

--

--

Osha Groetz

Software Engineer. React, Javascript, Typescript, HTML, CSS, Ruby, Ruby On Rails