使用令牌对GitHub进行身份验证 [英] Authenticate with GitHub using token

查看:2605
本文介绍了使用令牌对GitHub进行身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正尝试使用个人访问令牌对GitHub进行身份验证。在github的帮助文件中,它声明使用curl方法进行身份验证( https://help.github.com/articles/creating-an-access-token-for-command-line-use )。我已经尝试过,但仍然无法推送到GitHub。请注意,我试图从未认证的服务器(Travis-CI)推送。

config --global user.emailemailaddress@yahoo.com
git config --global user.nameusername

curl -u用户名:< MYTOKEN> https://github.com/username/ol3-1.git
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 -mTravis build $ TRAVIS_BUILD_NUMBER push to gh-pages
git push -fq origin gh-pages

这段代码会导致错误:


remote:匿名访问scuzzlebuzzle / ol3-1.git拒绝。



致命:< https://认证失败github.com/scuzzlebuzzle/ol3-1.git/ '


谢谢


curl 命令是完全错误的,您应该使用以下命令: $ b $ b

  curl -H'Authorization:token< MYTOKEN>'... 

除此之外,它并不授权您的计算机克隆存储库,但实际上它是私有的(但是,请注意,它不是)。 do是以下内容:

  git clone https:// scuzzlebuzzle:< MYTOKEN> ; @ github.com / scuzzlebuzzle / ol3-1.git --branch = gh-pages gh-pages 

这会将您的凭据添加到克隆存储库时创建的远程。然而,不幸的是,你无法控制Travis如何克隆你的仓库,所以你必须像这样编辑远程。

 #克隆后
cd gh-pages
git remote rm origin
git remote add origin https:// scuzzlebuzzle:< MYTOKEN> @ github.com / scuzzlebuzzle / ol3-1.git

这将修复您的项目以使用内置凭证的远程计算机。


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 (https://help.github.com/articles/creating-an-access-token-for-command-line-use). I have tried this, but still I cannot push to GitHub. Please note, I am trying to push from an unauthenticated server (Travis-CI).

cd $HOME
git config --global user.email "emailaddress@yahoo.com"
git config --global user.name "username"

curl -u "username:<MYTOKEN>" https://github.com/username/ol3-1.git
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/'"

Thanks

解决方案

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 https://scuzzlebuzzle:<MYTOKEN>@github.com/scuzzlebuzzle/ol3-1.git --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 rm origin
git remote add origin https://scuzzlebuzzle:<MYTOKEN>@github.com/scuzzlebuzzle/ol3-1.git

That will fix your project to use a remote with credentials built in.

这篇关于使用令牌对GitHub进行身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆