我正在尝试使用个人访问令牌与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 remote remove origin

然后:

git remote add origin https://<TOKEN>@github.com/<USERNAME>/<REPO>.git

你可以在这里找到如何生成你的身份验证令牌。

其他回答

从开发人员设置生成访问令牌后,运行这些命令, git push origin [branch]用户名为'https://github.com': [accessToken]密码为'https://[accessToken]@github.com':[accessToken]

首先,需要创建一个个人访问令牌(PAT)。描述在这里:https://help.github.com/articles/creating-an-access-token-for-command-line-use/

可笑的是,这篇文章告诉你如何创建它,但完全没有提供任何关于如何使用它的线索。在搜索了大约一个小时的文档和Stack Overflow后,我终于找到了答案:

$ git clone https://github.com/user-or-organisation/myrepo.git
Username: <my-username>
Password: <my-personal-access-token>

实际上,当我在远程工作时,公司的政策迫使我启用双因素身份验证,但仍然有本地更改,所以实际上我需要的不是克隆,而是推送。我在很多地方读到我需要删除和重新创建远程,但实际上我的正常推送命令与上面的克隆完全相同,远程没有改变:

$ git push https://github.com/user-or-organisation/myrepo.git
Username: <my-username>
Password: <my-personal-access-token>

(@YMHuang用文档链接让我找到了正确的方向。)

对于macOS,如果没有提示您输入用户名和密码请求,则意味着您的密码存储在Keychain Access中。每次你尝试克隆或推它将尝试使用您的旧密码。

遵循以下三个步骤来解决这个问题:

生成一个PAT(个人访问令牌)- LINK 打开钥匙链访问(通过聚光灯搜索)→搜索GitHub→单击GitHub→更改并保存与您的新PAT链接 尝试再次推送或克隆。现在您已经存储了PAT而不是密码。

Windows:

打开凭证管理器- Windows凭证 找到git的条目:https://github.com,编辑它 用PAT访问令牌替换以前的密码 解决了

Git远程删除原点 Git远程添加源https://{accesstoken}:{accesstoken}@gitlab.com/{username}/{repo}.git Git推送https://{youraccesstoken}@github.com/{username}/{repo}.git

这对我很有用。