mork
mork

Reputation: 89

Git pushes files to github with wrong username

I'm trying to push my committed changes to Github using Terminal on Mac OS but
it keeps saying that the access to the repository is denied to my old github user

Permission to myuser/test1.git denied to "OldUser". fatal: unable to access 'https://github.com/"NewUser"/test1.git/': The requested URL returned error: 403

I found some similar problems but none of the answers worked for me:
First of all Iv'e removed all the SSH keys from my mac and created a new one which I then synced with my github account.

Second, I have set the Global config for git to my new username and email using

git config --global user.name AND user.email

When I changed the user and email in the git local config file in my project dir (thinking at least that would work), I was surprised to see the same error when pushing, with my old user name popping out again.. (I really thought a local config would override any old global values) I just don't know where to look anymore..
There are no git environment variables defined and the SSH keys were all re-created. seems that the last option is to re-install git which would be a really ugly way out..

Oh! BTW when i'm trying to push to github using the dedicated MacOS app it works just fine! I wasn't surprised a bit because all users reporting this problem said that the app worked for them just fine.. Just thought I mention it!

So, if anyone got an answer (or at least a hunch) it would help me a lot.

Upvotes: 1

Views: 2836

Answers (2)

madrefactorer
madrefactorer

Reputation: 11

I had the exact same error on Windows and apparently it's a Git problem. Thanks to ayan4m1 at github forums (https://github.com/Microsoft/Git-Credential-Manager-for-Windows/issues/152) I finally fixed this issue in Windows using notepad in admin mode to delete the credential.helper = manager lines from the C:\Program Files\Git\mingw64\etc.gitconfig file. Nothing else worked.

Apparently since I was in non-elevated mode in Git bash from my IDE none of my global commands were able to overwrite the global file. Hope this helps and saves time for someone else with this issue.

Upvotes: 1

VonC
VonC

Reputation: 1324937

BTW when I'm trying to push to github using the dedicated MacOS app it works just fine!

It is possible the gitHub for Mac is using https url, with your GitHub login/password (which GitHub for Mac is caching).

Check the url associated with your remote origin:

git remote -v

If it is an https url (like your error message suggests "unable to access 'https://github.com/"NewUser"/test1.git/'"), no amount of SSH fiddling will change that error.
Maybe, for http url, the Credential Caching on Mac OS X has still the old credentials.

Upvotes: 3

Related Questions