Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

windows: git has old github username, cant change git user

Tags:

git

I have 2 github accounts, old and new. When I checkout a repo on the new, I cant commit it as it says my old github user is not authorised.

Lets say my old github account username is old, and email is [email protected] Lets say my new github account username is new, and email is [email protected]

The old github account has no SSH key associted with it. The new account has my ssh key. As I am using windows, ssh keys is something of a nightmare because putty/pagent uses ppk format, but openssh used by gitbash uses rsa. Some time ago, I managed to convert my ppk a rsa and put this in my windows users .ssh dir.

I have done this:

$ git config --global user.name new
$ git config --global user.email [email protected]

If I do this:

$ git config --global -l

or

$ git config -l

I see:

 [email protected]
 user.name=new

When I try to do $git push origin

remote: Permission to new/test.git denied to old.
fatal: unable to access 'https://github.com/new/test.git/': 
403 user old not authorised

I get this error if I use gitbash, tortoise or VS code to do the push.

If I delete the cloned repo, and clone it again from scratch, then commit anything, same problem.

$ git clone [email protected]:new/test.git

Any idea why and where its getting the old user? There is no reference to the old github users anywhere on my machine, and its blocking me from being able to do any work.

There seems to be no way to delete the old user from github, but even if I could, it may still not solve the problem. I have not been able to work for months because I cant commit anything to github.

Another thing I tried was to edit the .git/config after cloning the repo. I tried changing the https to ssh url, as https has never worked for me in all the years using github. https allows you to clone, but never to push. If I checkout with ssh, using the right amount of vodoo, it used to work, but now its always getting the old user for no obvious reason.

like image 903
John Little Avatar asked Jan 21 '18 13:01

John Little


3 Answers

unable to access 'https://github.com/new/test.git/':

That means: SSH is not involved. At all.
And user.name / user.email has nothing to do with authentication either.

Since you are using https, Git will use the first cached credential it finds for github.com.
Check the returned value of git config credential.helper
On windows, for instance, that would be the Windows credential manager.

You should at least specify the new GitHub account in your URL:

cd /path/to/your/local/repo
git remote set-url origin https://<newGitHubAccount>@github.com/newGitHubAccount/test.git

Then a Git push should trigger a popup asking you for your new GitHub account password.

If you want, you also can switch back to SSH.
You can manage multiple SSH keys as I describe here.

like image 69
VonC Avatar answered Oct 14 '22 07:10

VonC


user.name in your config is the username shown in commit messages - not the username used to authorise to a git repository.

When you are cloning the remote repo, what username are you passing to github/is in the url? For existing repos, what does git remote -v show?

Alternatively, you might be using a credential cache - can you try git credential-cache exit and see if this clears the cache?

like image 39
match Avatar answered Oct 14 '22 06:10

match


You can specify the username to use for authentication separately from the Git author name using credential.user. You can either set this globally (git config --global credential.user mylogin) or just for a single repository. That would sort it out for https authentication variation. Github with HTTPS does allow you to push. To debug issues there, run the git command under GIT_CURL_VERBOSE=1 to see the web headers. eg: GIT_CURL_VERBOSE=1 git ls-remote https://github.com/username/repo.git. If you enabled 2-factor authentication then you can't use your normal password, but must use a key you fetch from the website.

Note that puttygen can import an SSH RSA key-pair and convert it to a PPK key file and also do the reverse so you can convert keys from openssh to putty.

If you configure to use SSH keys then the key is used for your identity. You can run the git command under GIT_TRACE=1 to see what it is actually running. If it is putty/plink then you need to check the putty session information stored in the registry and see what key has been associated with the github session you are using. If openssh then the key should be in $HOME/.ssh/id_rsa and you can check which user key you have there.

like image 45
patthoyts Avatar answered Oct 14 '22 06:10

patthoyts