DEV Community

Cormac
Cormac

Posted on • Edited on

3 2

How to Manage Multiple Github Accounts

If you work for a company and code on the side you may need to manage multiple Github accounts from the same device.

Here's how to push from two different Github accounts locally

Step 1) Create SSH keys

For each SSH key pairs:
run ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

You'll be prompted: "Enter a file in which to save the key" so make sure to use a unique name like "company" or "personal".

Step 2) Add public key to Github

Follow these steps.

Step 3) Create an ssh config file

cd ~/.ssh
touch config

Enter something like this making sure to save after:

#personal account
Host github.com-personal
   HostName github.com
   User git
   IdentityFile ~/.ssh/personal
   IdentitiesOnly yes

#user2 account
Host github.com-company
   HostName github.com
   User git
   IdentityFile ~/.ssh/company
   IdentitiesOnly yes
Enter fullscreen mode Exit fullscreen mode

Step 4) Clone Repo

git clone git@github.com-company:REPOSITORY_NAME.git

Step 5) Edit config

You'll need to do this for each repo

Open up local git config using git config --local -e and add:

[user]
    name = company
    email = name@company.com
Enter fullscreen mode Exit fullscreen mode

type :wq and enter to save and quit

Step 6) Confirm your remote url

git remote set-url origin git@github-comcompany:REPOSITORY_NAME.git

Step 7) Git add commit and push

Now you can git actions (pull/push/fetch...etc) all you like!

Resources:
https://www.youtube.com/watch?v=R5yS23LKr04
https://gist.github.com/Jonalogy/54091c98946cfe4f8cdab2bea79430f9

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay