10

I was trying to setup a repo with an existing files. So I followed the simple instructions from the source but on the last step when I try to push, I got this error;

remote: Permission to abc/abc.git denied to abc@oldemail.com.
fatal: unable to access 'https://github.com/abc/abc.git/': The requested URL returned error: 403

So then I checked the current user by outputting the command;

git config user.email

which yields a different email from the error above. Also, tried authenticating into github which went successful with the command below.

ssh -T git@github.com

I only have one ssh-key and ssh-agent is also defined.

Any suggestions on how to further debug? Why is it using the oldemail instead of the current one?

Thanks!

P.S. I'm on a mac running yosemite.

admiralqxcvii
  • 111
  • 1
  • 5

4 Answers4

2

This has nothing to do with your config settings.

It has something to do with that the deploy key you are pushing with is attached to another repository. Something that happens if you work with two different (or more) github-users from the same local environment.

To take a look into your local system and which deploy keys you have, you can run: ls -al ~/.ssh in your terminal.

This will bring up a list of your existing keys.

My bet is that you have named one of your keys your email.

So it would look something like this:

-rw------- 1 bruger staff 3326 Jul 21 2020 abc@oldemail.com

If you follow Githubs own tutorial on setting up a deploy key you will soon have the right setup to connect to your repository without any problems.

Update

I have been reading about this for a while now, and i found this post that says that it has something to do with your local environment.

For example if you're on a Mac you can delete your credentials in Keychain Access (search for "github") and then try again.

Your computer saves the last push credential. You can also see more with git config.credential.helper

  • 1
    I think this is correct reason. At least I have repaired my own problem base on this. I add a separate anwser what I have done. – mirek Jan 18 '23 at 18:25
1

It would appear that you are attempting to connect with an email that GitHub does not recognise/associate with your account.

You can either:

A) Change the email address using git config, https://help.github.com/articles/setting-your-email-in-git/ to the email address associated with your github account.

B) Add the email address returned from the 'git config user.email' here: https://github.com/settings/emails

Also ensure that you do have write access to the repo you are trying to push to

Peter Reid
  • 5,139
  • 2
  • 37
  • 33
  • 8
    actually my github email settings is correct, it matches up the email from the output; git config user.email and also the repo is mine. I guess the question is how do I stop git from using the old email or is there some caching involve that I need to clear/update to use the current email? – admiralqxcvii Jul 22 '15 at 10:32
0

Github has collaborator settings now. It solves all my problem regarding this. Just goto Settings > Collaborators, and add abc@oldemail.com to it.

Lye Heng Foo
  • 1,779
  • 1
  • 10
  • 8
0

Yes, I think Peter Palluth answer is correct.

When I temporary kill the ssh-agent: eval $(ssh-agent -k) (I can rerun it later: eval $(ssh-agent)) then I can see at next push attempt that the ssh key for which I should enter its password is not the correct one, not the key which is uploaded on github/gitlab.

So I need force the proper one. I can edit ~/.ssh/config and create some Host like:

Host github-some-account
  HostName github.com
  PreferredAuthentications publickey
  IdentityFile ~/.ssh/id_ed25519_github_some_account

And now I need use in my git config this Host. I can repair in maybe git config --local -e the url item, I would change:

url = git@github.com:<user>/<repo>.git

to

url = git@github-some-account:<user>/<repo>.git

Then on github/gitlab go to Settings (at user level; however it could be set at repository level for each single repository too), SSH keys and make sure that you have SSH key there. If no, use cat ~/.ssh/id_ed25519_github_some_account.pub, copy the result to clipboard and paste it as New SSH key to github/gitlab.

Then retry git push.

mirek
  • 1,140
  • 11
  • 10