I need to have two GitHub accounts on my computer, one personal, and one for work. I browsed the internet to find a solution to not be obligated to retype my credentials every time, and I stumbled upon this tutorial explaining the SSH system. That entirely correspond to my need.
Situation: I can push/pull from existing projects. That would suggest that the SSH keys/config are working well.
Problem: I can't push when it comes to a new project. If it is a new project (also created as described in the tutorial), the push returns the following error:
xxx@xxx:~path/to/repo$ git push -u origin master
ERROR: Repository not found.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
This is the git config -l
on the repo:
xxx@xxx:~path/to/repo$ git config -l
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
user.email=<email>
user.name=<username>
remote.origin.url=git@github.com-<username>:<username>/test.git
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
And to be exhaustive, here is the SSH config file:
# Work account
Host github.com-<username1>
HostName github.com
User git
IdentityFile /path/to/ssh/key1
IdentitiesOnly yes
# Personal account
Host github.com-<username2>
HostName github.com
User git
IdentityFile /path/to/ssh/key2
IdentitiesOnly yes
Obviously, and in the repo are the same as the ones in the SSH config file, I checked that a couple of times.
Configuration:
- Ubuntu 20.04.3 LTS
- git version 2.25.1
- (let me know if there are additional information needed)
I found some other persons having a similar problem online, but the solution was never satisfactory in my case... (Either the SSH key was not added, which is not my case, or change from SSH to HTML, which is not possible if I want to use the SSH keys, as far as I have understood)
Thanks for any of your ideas!