我正在尝试使用个人访问令牌与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。辅助缓存

和工作

其他回答

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

最近github不允许直接从cmd使用我们的用户名和密码提交。为此,我们需要生成如下所述的访问令牌。

然后在命令提示符中使用相同的访问令牌作为用户名和密码,用于git命令git push, git pull等。例如

git push origin master
Username for 'https://github.com': lhq_4npmklMYXXXXXXXXXXXXXXXXXXXL8SxHxU
Password for 'https://lhq_4npmklMYXXXXXXXXXXXXXXXXXXXL8SxHxU@github.com':<give same access token here as password too>

你开始看到代码日志如下:

Enumerating objects: 24, done.
Counting objects: 100% (24/24), done.
Delta compression using up to 8 threads
Compressing objects: 100% (14/14), done.
Writing objects: 100% (18/18), 6.33 KiB | 539.00 KiB/s, done.
Total 18 (delta 5), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (5/5), completed with 2 local objects.
To https://github.com/xxxxxxxxxxx/xxx-xxxxx-repo.git
123456..1233456  master -> master

希望这能帮助到一些人。快乐编码!!:)

自动化/使用OAuth令牌的Git自动化

$ git clone https://github.com/username/repo.git
  Username: your_token
  Password:

它也适用于git push命令。

参考: https://help.github.com/articles/git-automation-with-oauth-tokens/

您可以轻松地更改远程认证,首先:

删除当前原点:

git remote remove origin

然后:

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

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

这对我使用ssh工作:

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

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