git insists on another username even with ssh keys

I've opened a new github account for school, and added my ssh keys to it, but when I try to push my local repository into it, I get:

ERROR: Permission to new-username/repo-name.git denied to old-username.
fatal: Could not read from remote repository.

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

any ideas? Thanks!


Solution 1:

and added my ssh keys to it

If your remote repository URL is an HTTPS one, no amount of SSH key will help.

Check your git config credential.helper: if it is set and, again, if you are using an HTTPS URL, chances are the credential helper has cached your old credentials.
You need to remove said credentials from the cache.


If your URL is indeed an SSH one:

  • check git config -l for any insteadOf directive which might change it to an HTTPS one.
  • make sure you key has a default name like ~/.ssh/id_rsa and id_rsa.pub (assuming an rsa key), in order to that key to be considered.

Try export GIT_SSH_COMMAND='ssh -Tv', then your git clone: you will see which key are considered.