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


当前回答

对于那些来自GitLab的人来说,对我有用的是:

先决条件:

创建令牌:

选择必要的权限 选择截止日期 通过按“创建个人访问令牌”生成 保存令牌!

步骤1。

添加遥控器:

Git远程添加origin https://<access-token-name>:<access-token>@gitlab.com/path/to/project.git

步骤2。

拉:

https:// < access-token-name >: <访问令牌> @gitlab.com/path/to/project.git

现在您可以从存储库中读取/写入数据了

其他回答

首先,需要创建一个个人访问令牌(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用文档链接让我找到了正确的方向。)

自动化/使用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/

步骤1:获取访问令牌

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

步骤2:使用令牌

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

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

这对我很有用。

Mac用户:

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