12

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 old@old.com Lets say my new github account username is new, and email is new@new.com

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 new@new.com

If I do this:

$ git config --global -l

or

$ git config -l

I see:

 user.email=new@new.com
 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 git@github.com: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.

John Little
  • 10,707
  • 19
  • 86
  • 158
  • The `user.name` and `user.email` configuration values doesn't play any role in the authentication to Github or somewhere else. They are used only locally when commits are created or modified. – axiac Feb 13 '18 at 11:18
  • Dies [this](https://stackoverflow.com/a/43144611/5784831) help? – Christoph Feb 13 '18 at 12:09
  • @Christoph it doesnt help directly, but it does beg the question is it using some cached user/pass rather than my certificate? If so, how do I clear it? – John Little Feb 13 '18 at 12:13
  • @JohnLittle "is it using some cached user/pass rather than my certificate?", yes, as I mention, but it is the https credential which is cached, and has nothing to do with an SSH certificate. – VonC Feb 13 '18 at 20:25
  • Is your question solved? How? – Christoph Feb 15 '18 at 20:23

5 Answers5

12

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.

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

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.

patthoyts
  • 32,320
  • 3
  • 62
  • 93
3

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?

match
  • 10,388
  • 3
  • 23
  • 41
  • FYI, am not passing any username in the clone URL. It is picking it up from config global user.email. If I unset this, then I cant clone - it says I need to set it. github uses the user.mail to associate the account. I used to use SSH clone URL, but lately if I do this, I cant commit. I have had to use the git: url to be able to commit after. – John Little Jan 21 '18 at 13:50
  • 2
    github doesn't use `user.email` for logins - only to associate commits with your account. If you are using an `http://` url - then a lack of username means it should either prompt for one, or else use the credential cache. For `git://` it will use your ssh keys, which are associated with an account in github - so you might need to generate new keys, or associate the existing key with the new account. – match Jan 21 '18 at 16:03
  • "git credential-cache exit" gives "credential-cache" is not a git command unfortunately. – John Little Feb 13 '18 at 11:16
  • It looks like windows might use a different helper - see: https://blog.sdbarker.com/post/git-credential-caching-on-windows-update/ – match Feb 13 '18 at 11:57
0

Try using 'credential.helper=manager' instead of 'credential.helper=store'. Had the same problem as John Little : even though I changed my username and email and the git config --list command correctly listed the new account values, I still could not get access to the remote repository, until I also changed credential.helper to 'manager'.

HTH, Remus

Golgot Remus
  • 86
  • 1
  • 3
0

Windows 10

Sometimes, the only solution might be to open Start > Credentials Manager and there add:

Url:  git:https://github.com
Username:   your_username
Pass:    your_app_password   (if you leave empty, it will ask password)

and after that, switch the local config to your matching username (others answered how to change).

T.Todua
  • 53,146
  • 19
  • 236
  • 237