Switching Github Accounts on Visual Studio Code with a MacBook

April Escobar
6 min readApr 5, 2021
Image Source

Introduction:

Graduating from a coding bootcamp, I knew very little about Github and git commands. I signed in once, connected it to my computer and that was it. It wasn’t until my first job that I realized I needed to switch git accounts on my MacBook. My immediate thoughts?

“None of my commits for work will show up on my personal git account 🥺 (i.e. my green tiles!!).”

Anyway, I got over it pretty quickly as learning on the job demanded more of my attention. My CTO walked me through setting up my new GitHub account for the company and made sure I had the right access to the private repository that held all of our application’s code.

It was all pretty much a blur since he was basically holding my hand (remotely of course), walking me through each step and debugging the issues for me.

So when it was time to go back into my personal account to work on my projects months later, I could not figure out why I wasn’t able to access my own repositories. Then I did a little bit more research and found out why!

I’m going to assume that both GitHub accounts are active and set up correctly. Meaning the SSH keys and such are already taken care of 😙.

Where to update:

  1. GitHub
  2. Visual Studio Code
  3. Terminal
  4. Keychain Access

In this walk through, I’ll use my company account as the current account signed into everything. The goal is to switch to my personal account.

1. GitHub:

Image Source

The main source for linking everything is your GitHub account. So the first place we need to update is just that. This one is pretty easy.

  • Sign out of your current account (e.g. company account).
  • Sign into the account with the appropriate access to the repositories you need (e.g. personal account).

2. Visual Studio Code:

Image Source

Next, we need to update your Virtual Studio Code application or VS Code for short. Only follow these steps once you’re signed into the desired account (e.g. personal account) on your GitHub since we’re linking VS Code to…well… your GitHub.

  • At the bottom left corner of your VS Code, you’ll see a profile icon.
  • Sign out of your current account (e.g. company account).
  • Then, turn on your Settings Sync.
  • You will be prompt to authorize Visual Studio Code to access GitHub on a browser. This is why you need to be logged into your desired account (e.g. personal account)on GitHub first.
  • Press ‘Continue’ to proceed.

3. Terminal:

Once we have our GitHub and VS Code linked, the next update we need to make is on your terminal. Whether you’re using a standard terminal or the terminal provided on your VS code, let’s first find out the account you’re currently signed into with the following commands:

git config --global user.name 
git config --global user.email

Here, I’m currently signed into my company’s account via email. Since I use the same name on both GitHub accounts, I really only need to update the email portion. We can do so with the following command:

git config --global user.email ‘<email_address>’

In case you need to update your name, here’s the command for that.

git config --global user.name ‘<first_name last_name>’

Let’s check it again for good measure.

git config --global user.email

Everything looks good! Or so I thought…

Here’s where I got stuck. After completing steps 1–3, I thought I was good to go. I went about and coded my life away with my personal project. But then, when it was time to push the changes onto GitHub, I got this error message:

(I switched over to using the terminal on VS Code)

This error message is saying two things.

  1. I’m still signed on as my company account.
  2. Because of that, my permission to push changes onto my personal repository got denied.

I didn’t understand why I was still signed into my company account when I thought I made all the necessary changes. I even double checked my terminal to make sure my email was indeed updated.

git config --global user.email

Yup, everything was definitely updated to my personal account. So what was causing the error?

Well, little did I know that MacBooks have this handy dandy tool called Keychain Access that automatically stores passwords and account information. So what’s happening is that this tool still has my company account information stored, preventing me from accessing my personal repository. This is actually a super easy fix!

My CTO probably walked me through this part too, but again it was all such a blur… Anyway, this is the final place we need to update in order to successfully switch GitHub accounts on our VS code with a MacBook.

4. Keychain Access:

What we need to do in this last step is to delete the stored GitHub data in our Keychain Access.

I know, I know, deleting something in our system is a scary concept or at least it was to me because I wasn’t too sure what I was doing. For those feeling the same way, let me explain why we’re deleting the stored GitHub data.

Keychain Access currently has my company GitHub account stored. The only way to access my personal repositories is by deleting this stored data. And don’t worry, once we delete this data, our MacBook will automatically stores the new account information in the Keychain Access. So no harm done! But when we want to switch back to the company account, we’ll need to delete the stored data again since it’ll contain my personal account.

It’s genuinely the same concept as the previous three steps. Personally, this one just seemed a little scary because I’ve never (consciously) utilized Keychain Access before. I hope this eases your mind a bit and you’ll see it’s really not that bad!

If you don’t know where to find Keychain Access, the easiest way to do so is to use the Spotlight Search by pressing the command(⌘) + space key. It should look something like this:

Enter “Keychain Access” and once you hit the return key, the application will open.

  • Once opened, the first thing we need to do is unlock our keychain system by right-clicking on the “System”.
  • Enter “GitHub” in the search bar.
  • Delete the stored data by selecting both rows and right-clicking on them.

Now when we try to push our code again, VS Code will prompt to allow GitHub to access the application.

  • Click on “Allow”.
  • Click on “Continue” to proceed.
  • “git push” one more time on your terminal and experience the beauty of a successful connection and push

--

--