Unable to set GitHub access token

Viewed 986

When I try and git clone any repository using HTTPS, it will not prompt me for my access token, I just get a 403 error. git clone using SSH does work fine. I suspect the problem is related to being on a company laptop that uses ZScaler and HTTPS trust\certificate chain is broken.
How does git know what certificates to use, like a browser does? or how can I troubleshoot this?

$ git clone https://github.com/GoogleCloudPlatform/python-docs-samples.git
Cloning into 'python-docs-samples'...
fatal: unable to access 'https://github.com/GoogleCloudPlatform/python-docs-samples.git/': The requested URL returned error: 403

I have tried to remove all references from my KeyChain so it will prompt me again for my Access Token but it never does. Also I can not see any reference to git in the OSX KeyChain

My local git is set to use osx KeyChain

$ git config --get-all --show-origin credential.helper
file:/Applications/Xcode-11.3.1.app/Contents/Developer/usr/share/git-core/gitconfig     osxkeychain

But it seems to know my GitHub credentials for my company's corporate GitHub

$ git credential-osxkeychain get

password=<my company password>
username=<my company logon>

Where is git getting my username and password from for my Company's corporate GitHub and how can I tell git to use my credentials & access token for GitHub.com?

Update 1

$ git credential-cache exit
$ git credential-osxkeychain erase
host=github.com
protocol=https

$ git config --global --unset credential.helper

Now this command returns nothing

$ git credential-osxkeychain get

But still get the 403 error, even using my GitHub username as per suggestion below, it does not prompt me.
I've double checked my KeyChain and there is nothing stored there for GitHub

2 Answers

A good tip to incite the credential helper to ask for your credential with your correct login is to add said login to your GitHub URL:

 git clone https://<MyGitHubAccount>@github.com/GoogleCloudPlatform/python-docs-samples.git

And make sure you have removed any GitHub entry from the OSX Keychain

Then it should prompt for your password.

Finally found a solution

$ git config --global url.git://github.com.insteadOf "https://github.com"

This forces the git protocol for public github sites without authentication while still working within the corporate network and our private GitHub repositories

Related