Managing multiple Github Accounts

Oh no, why is my work not being pushed up to my GitHub!?
  1. Create ssh file locally
  • Before creating a new file, make sure you are in the appropriate directory. I created my ssh file under Users/gracenakano and then cd (stands for change directory) into the newly created file.
Users/gracenakano touch .ssh
Users/gracenakano cd .ssh
  • Enter your personal email address associated with the account
Users/gracenakano cd .ssh
.ssh ssh-keygen -t rsa -b 4096 -C "personal_email@gmail.com"
.ssh id_rsa_personal
  • Go through the same process to generate a rsa key pair for your work account, entering the work email associated to your work GitHub account.
.ssh ssh-keygen -t rsa -b 4096 -C "work_email@gmail.com"
.ssh id_rsa_work
.ssh ls
id_rsa_personal id_rsa_personal.pub id_rsa_work id_rsa_work.pub
.ssh cat id_rsa_personal.pub
  • Take the return SSH key value and copy and paste into your GitHub account.
  • In your GitHub account, go to Settings => SSH and GPG keys => New SSH Key.
  • Add title to key. You can call it anything such as “Grace’s MacBook”. Paste the SSH key to the body. Click Add SSH key
  • Repeat the process for your work account. Make sure to log out of your personal Github account and sign into your work account before continuing the process.
.ssh cat id_rsa_work.pub
  • You can title the key the same in your work account. Just make sure to copy and paste the correct SSH key.
.ssh touch config
.ssh nano config
# Personal account - default config
Host github.com-gracenak
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_personal
# Work account
Host github.com-gracenakano
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_work
  • Let’s start with the personal account:
.ssh cd
~ nano ~/.gitconfig
  • Add to the file:
[user]     
name = Grace Nakano
email = personal_email@gmail.com
[includeIf "gitdir:~/work/"]
path = ~/work/.gitconfig
~ mkdir work
~ nano ~/work/.gitconfig
  • Add to file:
[user]     
name = gracenakano
email = work_email@gmail.com
~ cd .ssh/
.ssh ssh-add id_rsa_personal
.ssh ssh-add id_rsa_work
# to see our list of keys .ssh ssh-add -l
# personal
.ssh ssh -T github.com-gracenak
// prompt to continue => yesHi gracenak! You've successfully authenticated, but GitHub does not provide shell access# work
.ssh ssh -T github.com-gracenakano
// prompt to continue => yesHi gracenakano! You've successfully authenticated, but GitHub does not provide shell access
  • add hostname in the following (indicated in bold below)
~ cd work/
work git clone git@github.com-gracenakano:gracenakano/test.git
  • we can check to see if we have cloned down and connected to the correct GitHub account
work cd test/
work/test git config user.email
work_email@gmail.com
  • follow the same procedure for your personal account by cloning down a personal repository via SSH and add host name as sampled above.
  • create branch and add file
work/test git checkout -b test
work/test touch test.rb
work/test
git add .
work/test git commit -m"add test file"
work/test git log
Author: gracenakano <work_email@gmail.com>
work/test git push origin test
# pushes branch remotely
  • if we check our GitHub account, we should be able to see the new branch pushed up and merge it to our repository.

--

--

--

Fullstack Software Engineer | Musician | Food Lover | Coffee Addict

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Kubernetes Tutorial: Running a Rails App in Kubernetes

Running a Rails App in Kubernetes

How to Build a Video Chat App

Conditional/Branching Statements in Python

How UPS is saving millions through their digital transformation

Changelog — August 2020

The tone seems unprofessional.

Laravel Benchmark with Locust

Microservices Boot Camp Part 1

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Grace Yuiko Nakano

Grace Yuiko Nakano

Fullstack Software Engineer | Musician | Food Lover | Coffee Addict

More from Medium

Magento Open Source vs Adobe Commerce: What Should You Choose

Workflow with Strapi (Headless) CMS

[Jira-Part 1] Create a first issue in Jira

Fake Documents Editing Service