我正在尝试使用个人访问令牌与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远程删除原点 Git远程添加源https://{accesstoken}:{accesstoken}@gitlab.com/{username}/{repo}.git Git推送https://{youraccesstoken}@github.com/{username}/{repo}.git

这对我很有用。

其他回答

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

步骤1:获取访问令牌

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

步骤2:使用令牌

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

使用新的访问令牌更新远程回购

git remote set-url origin https://{{your_username}}:{{your_new_token}}@github.com/{{repo_path}}.git

因为我使用的是macOS,所以我可以专门为macOS回答这个问题。 我们也可以在Windows上使用这个。它的工作原理! 在你的GitHub帐户中,点击右上角的头像,进入设置配置文件。

点击设置:

点击开发者设置:

点击个人访问令牌:

然后点击Generate new token:

为您的访问令牌提供一个名称,并检查第一个选项。

向下滚动并单击generate token

现在,当你推送repo时,使用以下语法:

git remote add origin https:<access__token>://@github.com/<username>/<repo__name>.git

git push https://<access__token>@github.com/<username>/<repo__name>.git

在我看来,你可以使用第二种选择,同时按下回购提供访问令牌,你就可以了。

在Android Studio中选择vcs→push标签。弹出窗口将显示用户名和密码。输入您的用户名,而不是密码,输入令牌号码。它会被推送到存储库。