Question:
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).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
cd $HOME git config --global user.email "emailaddress@yahoo.com" git config --global user.name "username" curl -u "username: git clone --branch=gh-pages https://github.com/username/ol3-1.git 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 ‘https://github.com/scuzzlebuzzle/ol3-1.git/'”
Answer:
Your curl
command is entirely wrong. You should be using the following
1 2 |
curl -H 'Authorization: token |
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:
1 2 |
git clone https://scuzzlebuzzle: |
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.
1 2 3 4 |
# After cloning cd gh-pages git remote set-url origin https://scuzzlebuzzle: |
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.