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?

5
  • Are you using SSH or HTTPS? Commented Jan 28, 2021 at 7:21
  • 5
    user.name and user.email are not used for authentication. They are only used to write name and email address in your commits. Commented Jan 28, 2021 at 7:38
  • @mousetail I am using https. Commented Jan 28, 2021 at 7:41
  • @j6t I think so, but what is the solution. Commented Jan 28, 2021 at 7:42
  • Can you check this answer and see if it's related to osxkeychain credential helper and the credential.helper? Commented Jan 28, 2021 at 8:07

1 Answer 1

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://[email protected]/<username2>/repo
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.