Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Two github accounts to push to same repo [duplicate]

Tags:

git

github

So this is a very specific use case. It would be great if any GitHub gurus can help me.

In my Linux laptop, I want to push to same GitHub repo using two different GitHub usernames.

I have setup both the SSH keys in my local machine. I have been able to configure it up until being able to switch between users when committing. This works fine and I can switch between the two configured users while committing.

However whenever I do git push I am never able to switch users and it always uses my first username.

Is there a way I can switch or select user when I push to github?

like image 201
Undefined Variable Avatar asked Dec 07 '25 18:12

Undefined Variable


1 Answers

paraphrasing this answer :

You can create two different hostnames in your ~/.ssh/config.
For example, if your configuration looks like this:

Host github-as-alice
  HostName github.com
  User git
  IdentityFile /home/whoever/.ssh/id_ed25519.alice
  IdentitiesOnly yes

Host github-as-bob
  HostName github.com
  User git
  IdentityFile /home/whoever/.ssh/id_dsa.bob
  IdentitiesOnly yes

Then you just use github-as-alice and github-as-bob instead of the hostname in your URL:

git clone github-as-alice:name/whatever.git
cd whatever
git remote add bob github-as-bob:name/whatever.git

note: you can also have a "by default" key for github by simply mentioning it in a Host github.com section :

Host github.com
  User git
  IdentityFile /home/whoever/.ssh/id_ed25519.github
like image 127
LeGEC Avatar answered Dec 10 '25 10:12

LeGEC



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!