2

I have set my global github user settings in my computer.

  • user.name "myusername"
  • user.email "myemail"

I have second github account with a different name "myusername2". I cloned a repository from "myusername2" account to my computer. But global user settings are "myusername". So I set the username and email using command:

git config user.name "myusername2"
git config user.email"myemail2"

But when I push commits, the authentication error occured. I think this is for password not authenticated. So how can I solve this problem?

barteloma
  • 6,403
  • 14
  • 79
  • 173

1 Answers1

4

If an authentication error occurs when pushing with an HTTPS URL, this is because the cached credentials stored by the credential helper (check what git config credential.helper returns) are wrong.

To force said credential helper to select the right account, I would add the username in the HTTPS url:

cd /path/to/local/repo
git remote set-url origin https://username2@github.com/<username2>/repo
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250