VladislavShcherba
VladislavShcherba

Reputation: 460

Git tries to push commit to GitHub as wrong user

I have two GitHub accounts. First is main, second is for some tests (I'm new in git). In my C:\Users\<Username>\.gitconfig file I have user name and email similar to main GitHub account. Now I've created local repository and change its .git\config file with username and email similar to my second account. But still when I push, it tries to push as user of main account and I have this error:

 Permission to <2nd username>/test.git denied to <1st username>.

I thought that only email address is a way how git and GitHub are bounded, and that .git\config will override C:\Users\<Username>\.gitconfig for that repository.

But it seems that I'm wrong...

UPD:

As I remember in my very first push to GitHub git opened a window where I was needed to enter login and password of GitHub. And I entered main account login and paswsword. I have expected that this window opened again, after i tryed to push with new email...

Upvotes: 0

Views: 203

Answers (1)

Lasse V. Karlsen
Lasse V. Karlsen

Reputation: 391286

Git by itself doesn't care which name and/or email address you use when you commit when dealing with pushes.

All it cares about is whether it is allowed to push or not.

The last paragraph in your question is the important bit. You've told git to use your 1st account when authenticating with github, and now you're trying to push to your 2nd account without the 1st account having access.

Again, what you have told git to use when committing is completely irrelevant at this point.

To switch to the 2nd account find and open "Windows Credential Manager", find your github account setting and delete it, then try to repush. Git should again ask you for login details.

Or, give the 1st user push access to the 2nd users repository.

Upvotes: 1

Related Questions