0

I am trying to use a personal account and a more work-related account on Github.

So my first account is already working all fine. For my second account, is it possible just to go into my folder,

# make sure `git init` already and is a git repo
git config user.name   "the other UserName"            # note, without --global
git config user.email  "the.other.email@gmail.com".  

and now, create another ssh key, and add that public key to GitHub. (But I didn't go the ssh-agent part as on Github's instruction).

So from now on, whenever I want a project to be owned by the "alternative account", just go into that folder and set that local user. name and user. email by those 2 git config lines above, and it should work?

But the thing is, I tried that and when I git push, it says:

Please make sure you have the correct access rights and the repository exists.

Can I make it work by using this method?

  • https://stackoverflow.com/search?q=%5Bgit%5D+multiple+accounts – phd Feb 15 '21 at 10:32
  • 1st you need configure SSH to use different keys. As SSH can separate keys only per host you have to configure different hosts in `~/.ssh/config` even if the hostname is just the same `github.com`. Then you need to configure remote URLs in git repositories to be that different SSH hosts. – phd Feb 15 '21 at 10:34
  • can't I use 1 key for both github account just by adding the key to the SSH section on github? – deeper-understanding Feb 15 '21 at 13:42
  • No. How would Github distinguish one account from the other? When the user is always `git` (in SSH URL `git@github.com`) the only way to separate accounts is by using different keys. But you can use one key on different hosts (Github, Gitlab, Bitbucket, local, etc…) – phd Feb 15 '21 at 13:59
  • @phd can't Github tell by (1) me pushing to that repo, and (2) by my git config email matching that account's email? – deeper-understanding Feb 15 '21 at 17:50
  • Nop. Email is not a credential. Only login+password for HTTP(S) URLs and SSH keypair for SSH URLs. – phd Feb 15 '21 at 20:02
  • @phd so the key has my email tagged at the end... that means one pair of keys, only for 1 email address? – deeper-understanding Feb 16 '21 at 07:37
  • It's a comment, it's not used in any way. You can generate a hundred of keys with any comments, emails, whatever. – phd Feb 16 '21 at 09:13

0 Answers0