1

I am trying to set up git with a work account and a personal account. I'm quite new to git.

I am able to push to the work account, but when trying to push to the personal account, I get the following error:

ERROR: Permission to <personal_repo> denied to <work_github_username>.
fatal: Could not read from remote repository.

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

My ssh config looks like this:

# Personal account, - the default config
Host github.com-<personal_github_username>
   HostName github.com
   User git
   IdentityFile ~/.ssh/<name_of_personal_private_key_file>

# Work account
Host github.com-<work_github_username>
   HostName github.com
   User git
   IdentityFile ~/.ssh/<name_of_work_private_key_file>

If I do git remote -v I get: origin git@github.com:<personal_github_username>/<repo_name>.git (fetch) origin git@github.com:<personal_github_username>/<repo_name>.git.git (push)

Chessnut
  • 65
  • 5
  • https://stackoverflow.com/a/3860139/7976758 Found in https://stackoverflow.com/search?q=%5Bgithub%5D+multiple+accounts – phd Jul 02 '22 at 10:25
  • Please show your `git remote` for the personal repository. Is the URL `git@github.com-` ? – phd Jul 02 '22 at 10:26
  • 1
    Note that you will usually want `IdentitiesOnly yes` (see https://stackoverflow.com/q/3225862/1256452). – torek Jul 02 '22 at 10:29
  • 2
    `git remote set-url origin git@github.com-:/.git` – phd Jul 02 '22 at 10:33
  • Thank you @phd ! That works. Do I need to run that every time I made a new repo? Is that the best way to do it? – Chessnut Jul 02 '22 at 10:39
  • 1
    @Chessnut For every new repo you do `git init` — yes, either `git@github.com-` or `github.com-`. When you `git clone` just use the proper URL in the command — it'll be stored in `.git/config` so you don't need to change it. – phd Jul 02 '22 at 10:43
  • Thank you @phd! Greatly appreciated. Out of curiosity, what does adding the ending to `git@github.com-` do? If I type in github.com to the address bar in my browser, it does a regular search, whereas github.com doesn't. – Chessnut Jul 03 '22 at 10:11
  • 1
    Git doesn't process the URL, it passes the URL to SSH and SSH looks it up in `~/.ssh/config` – phd Jul 03 '22 at 11:05
  • Gotcha, thanks for all your help :) I think I'm good now – Chessnut Jul 03 '22 at 11:13

0 Answers0