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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With