1

I created repo on the GitHub remote, cloned it on the local. I configured Git username and email using:

git config --local user.name "firstname lastname"
git config --local user.email "first.last@gmail.com"

git remote show origin is also giving the correct upstream But when I add files, commit and try to push using:

git push origin master

I am getting error as:

remote: Permission to username/project.git denied to randomuser.

I don't know from where the randomuser is coming from. When I do: git config --list --local I am getting the correct username and email. I need help to figure out how it is happening and how to overcome it?

gd1
  • 655
  • 1
  • 10
  • 21

2 Answers2

2

The username/email set in Git has nothing to do with authentication on GitHub, and is only used for commit authorship.

It depends on your remote origin URL: SSH (git@github.com:...) or HTTPS (https://github.com/...)

In the former case, check your ~/.ssh/id_rsa(.pub) keys.

In the latter case, check our git config credential.helper output: the credentials manager could cache the wrong credentials ("randomuser" for github.com).

If it is "manager", you can "sign out in the Git Bash console in Windows".

git credential-manager reject https://github.com

On Mac, for osxkeychain, see "Updating credentials from the OSX Keychain"

git credential-osxkeychain erase https://github.com

Then try again: it will prompt for user GitHub username/password.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
0

A very quick solution I found was * I am using macOS btw *, I went to the keychain, searched GitHub, deleted all of those saved passwords, and then returned to the terminal and re-entered the command.

Problem was solved.