我正在尝试使用个人访问令牌与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/'认证失败"


当前回答

步骤1:获取访问令牌

访问这个链接:https://github.com/settings/tokens。然后生成令牌。 或者从你的Github账户,转到: 设置->开发者设置->个人访问令牌

步骤2:使用令牌

git推 用户名:<用户名> 密码:<访问令牌>

其他回答

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

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

我以前使用密码使用Git CLI访问我的私有存储库,并使用Git config—global credential保存了我的凭据。辅助存储。

由于今天已经放弃了对密码的支持,我无法使用git配置命令建议的令牌更新我的凭据。

如果其他人在Linux上也有这个问题,您可以手动更新~/。git-凭据文件,例如

nano ~/.git-credentials

在:和@符号之间输入标记。(保存并关闭文件,按Ctrl + O, Enter, Ctrl + X)。

你可能还必须在证书文件中更新你的令牌后运行以下命令(参见@guhur的评论):

git config --global credential.helper store

注意,通过使用Git的凭据助手,任何有权访问您的主目录的人都可以看到您的令牌。

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

用于登录github.com门户的密码在Visual Studio Code CLI/shell中不起作用。您应该通过生成一个新令牌来从URL https://github.com/settings/tokens复制PAT令牌,并将该字符串粘贴到CLI中作为密码。

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

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