我正在尝试使用个人访问令牌与GitHub进行身份验证。在GitHub的帮助文件中,它声明使用cURL方法进行身份验证(创建个人访问令牌)。我已经尝试过了,但是我仍然无法推送到GitHub。请注意,我正试图从未经验证的服务器(特拉维斯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

这段代码会导致以下错误:

remote:匿名访问scuzzlebuzz /ol3-1。git否认。

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


当前回答

克隆你的项目-> git克隆https://token@github.com//project.git 在项目文件夹-> git配置-global credential。辅助缓存

和工作

其他回答

我为这个问题所困扰,但我找到了解决办法:

git push https://github.com/<username>/<project_name>
and
username: paste your personnal access token
password: paste your personnal access token

我必须添加oauth或oauth2作为用户名才能成功验证:

https://oauth:<TOKEN>@github.com/user/repo.git

Mac用户:

打开钥匙链访问,找到GitHub 右键单击GitHub 单击“删除” 打开终端并尝试克隆一个私有项目 添加所需的值 用户名:$your GitHub用户名 密码:$粘贴令牌在这里 然后按Enter键。Voilà—已添加令牌。

这对我使用ssh工作:

设置→开发人员设置→生成新的令牌。

git remote set-url origin https://[APPLICATION]:[NEW TOKEN]@github.com/[ORGANISATION]/[REPO].git

您的curl命令完全错误。你应该使用下面的方法

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

除此之外,这并没有授权您的计算机克隆存储库,如果它实际上是私有的。(然而,看一看,事实并非如此。)你通常会做的是:

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

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

# After cloning
cd gh-pages
git remote set-url origin https://scuzzlebuzzle:<MYTOKEN>@github.com/scuzzlebuzzle/ol3-1.git

这将使您的项目能够使用内置凭据的远程设备。

警告:令牌具有读/写访问权限,应该像密码一样对待。如果您在克隆或添加远程时将令牌输入到克隆URL中,Git会以纯文本的形式将其写入您的. Git /config文件,这就存在安全风险。