2

I am using the following commands to change my user details:

git config --global user.name myusername
git config --global user.email myemail

I pulled a public remote repository from account linked with myusername and when I was trying to push changes it gave the following error:

remote: Permission to myusername/project.git denied to oldusername.

Although I changed it, it still tries to push through the old username only. Why? What am I missing here? After checking the git config user.name, I found out that it shows myusername only and not the oldusername!

  • The user name and email address is used when committing, it isn't used when authenticating with a remote during a push, that's done either using a separate username and password, or a ssh key, depending on the remote url. Most likely you have an old ssh key that you're using that isn't added to the remote repository and given push access. What you stamp into each commit is rather irrelevant to this process. – Lasse V. Karlsen Apr 17 '17 at 21:13

2 Answers2

3

See Jordan Lewis's answer for why the push itself fails.

Note, however, that your configured user.name and user.email are used on commits you make, from the time you configure them.

Hence if you already made three commits with an old user.name and/or user.email, then change them and make one new commit, you now have four commits, three with the old name and one with the new.

When you run git push you tell your Git to offer, to their (other) Git, all commits you have that they don't have. That would be all four of these commits. (And if that newest commit you made has, as its parent, one of the three "wrong name" commits you made, your Git must send both the wrong-name and right-name commits for your latest right-name commit to get added.)

See also this answer to a related question, for help in copying the commits you made with the "wrong" name/email to new ones with corrected name/email.

Community
  • 1
  • 1
torek
  • 448,244
  • 59
  • 642
  • 775
3

The problem might be that you're pushing with a key that's attached to your oldusername account, but that key isn't added to your myusername account.

There's a help document that describes exactly this issue.

Jordan Lewis
  • 16,900
  • 4
  • 29
  • 46