2

I have two github accounts. I have created SSH keys for both, and configured them accordingly. I know that my config works because I can push to both accounts for my personal repos fine. Example config

Host github.com
etc
IdentityFile: id_rsa

Host github-second
etc
IdentityFile: id_rsa_second

To add remote for my normal account, I use git remote add origin git@github.com:account/repo.git To add remote for the second account, I use git remote add origin git@github-second:second-account/other-repo.git

I am now a member of an organization with my second account. The url for the repo of interest looks like github.com/organization/org-repo vs github.com/second-account/org-repo. I have tried to add the org repo using: git remote add origin git@github-second:organization/org-repo and I indeed got the repo files on my local machine. However, I cannot push to the org repo. Error:

fatal: Could not read from remote repository.
Please make sure you have the correct access rights and the repository exists.```

I have contacted the organization and they said that I have full write access. 
I am not sure what else to try.
Sandra
  • 76
  • 1
  • 8
  • Try `git remote add origin git@github.com:second-account/other-repo.git` instead, if your repos are all on github. – Niloct Nov 16 '21 at 20:24
  • @Niloct I tried that too. But for a sanity check, I tried again. And I get the same error. I have also tried: `git remote add origin git@github:second-account/organization/org-repo.git` to no avail. – Sandra Nov 16 '21 at 20:36
  • `git@github-second:` doesn't make sense, `github-second` is the domain that hosts the git repository and your question points it should be `github.com`. – Niloct Nov 16 '21 at 20:46
  • 1
    @Niloct my understanding is that different github accounts should have different hosts in the config, but hostname can be the same (github.com). The id_rsa should be different. Since the organization permissions are on the second account, I think that when I use ```git@github.com```, I am pointing to the first account, which does not have permissions for the organization. – Sandra Nov 16 '21 at 21:47
  • 1
    Ref: https://stackoverflow.com/questions/30068298/git-fatal-could-not-read-from-remote-repository-please-make-sure-you-have-th – Sandra Nov 16 '21 at 21:56
  • @Sandra Start debugging with `ssh -Tv git@github-second` . Add the output to the question. – phd Nov 16 '21 at 23:21

1 Answers1

1

I fixed it by:

  1. Re-adding the id_rsa_second
  2. Check ssh -T git@github-second and make sure it is pointed to second-account
  3. git remote add origin git@github-second:second-account/org-repo.git
  4. git remote add upstream git@github-second:org-account/org-repo.git
  5. Push to upstream. Hopefully, this helps someone else.
Sandra
  • 76
  • 1
  • 8