Authenticate with Github Using a Token
I Am Trying to Authenticate with Github Using a Personal Access Token. in the Help Files at Github, It States to Use the cURL Method to Authenticate (Creating...
I am trying to authenticate with GitHub using a personal access token. In the help files at GitHub, it states to use the cURL method to authenticate (Creating a personal access token). I have tried this, but I still cannot push to GitHub. Please note, I am trying to push from an unauthenticated server (Travis CI).
cd $HOME
git config --global user.email ""
git config --global user.name "username"
curl -u "username:<MYTOKEN>"
git clone --branch=gh-pages gh-pages
cd gh-pages
mkdir buildtest
cd buildtest
touch asdf.asdf
git add -f .
git commit -m "Travis build $TRAVIS_BUILD_NUMBER pushed to gh-pages"
git push -fq origin gh-pages
This code causes the errors:
remote: Anonymous access to scuzzlebuzzle/ol3-1.git denied.
fatal: Authentication failed for '"
31 Answers
Your curl command is entirely wrong. You should be using the following
curl -H 'Authorization: token <MYTOKEN>' ...
That aside, that doesn't authorize your computer to clone the repository if in fact it is private. (Taking a look, however, indicates that it is not.) What you would normally do is the following:
git clone --branch=gh-pages gh-pages
That will add your credentials to the remote created when cloning the repository. Unfortunately, however, you have no control over how Travis clones your repository, so you have to edit the remote like so.
# After cloning
cd gh-pages
git remote set-url origin
That will fix your project to use a remote with credentials built in.
Warning: Tokens have read/write access and should be treated like passwords. If you enter your token into the clone URL when cloning or adding a remote,
Git writes it to your .git/config file in plain text, which is a security risk.
First, you need to create a personal access token (PAT). This is described here:
Laughably, the article tells you how to create it, but gives absolutely no clue what to do with it. After about an hour of trawling documentation and Stack Overflow, I finally found the answer:
$ git clone
Username: <my-username>
Password: <my-personal-access-token>
I was actually forced to enable two-factor authentication by company policy while I was working remotely and still had local changes, so in fact it was not clone I needed, but push. I read in lots of places that I needed to delete and recreate the remote, but in fact my normal push command worked exactly the same as the clone above, and the remote did not change:
$ git push
Username: <my-username>
Password: <my-personal-access-token>
(@YMHuang put me on the right track with the documentation link.)
This worked for me using ssh:
Settings → Developer settings → Generate new token.
git remote set-url origin TOKEN]@
Automation / Git automation with OAuth tokens
$ git clone
Username: your_token
Password:
It also works in the git push command.
Reference:
I generated a token using the instructions from Creating a personal access token.
To actually use it, the following sequence worked for me:
git remote remove origin
git remote add origin
git push
Must Read
Step 1: Get the access token
Go to this link: . And generate the token there.
Or from you Github account, Go to:
Settings -> Developer Settings -> Personal Access Tokens