Home > Blockchain >  How to use personal access token with HTTPS urls from GitHub?
How to use personal access token with HTTPS urls from GitHub?

Time:12-23

I want to use Peronal access token with git repo on GitHub. I've created the token. And created a test repo. I used the Access Token as my password as I use to do. But git gives an error that password authentication was removed in 2021.

$ git remote add origin https://github.com/jcubic/git-test.git
$ nano README.md
$ git add README.md
$ git commit -am 'init commit'
$ git push
remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/jcubic/git-test.git/'

The documentation says:

When Git prompts you for your password, enter your personal access token.

But it doesn't work. What I'm doing wrong? Or what could be possible issues?

CodePudding user response:

I've contacted GitHub support and the error message was misleading. The actual error is: "that token needs write permission". I didn't check that option when creating a token, because the documentation that GitHub provides is also misleading. It says that "repo" permission is needed to access private repos, that may be right, but you also need "repo" permission if you want to push changes to the git repo.

So there are two bugs on the GitHub side here, one with a misleading error message and one with misleading documentation when creating an access token.

CodePudding user response:

If you did not enter your token, if there was no prompt, check your git --global credential.helper value.

If you have a credential storage set, check what credentials were registered for github.com:

printf "host=github.com\nprotocol=https" | git credential-xxx get

(replace xxx by your credential.helper value)

If you see your GitHub account password, instead of your token, that would explain the error message.

Change it with:

printf "host=github.com\nprotocol=https\nusername=jcubic\npassword=yourToken" | git credential-xxx store

If the token is there, double-check its scope

repo: Grants full access to public and private repositories including read and write access to code, commit statuses, repository invitations.

You can see the scope of a token with (as in this thread) gh repo list, to extract the X-Oauth-Scopes field

DEBUG=api gh repo list
  • Related