我正在尝试使用个人访问令牌与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 CLI访问我的私有存储库,并使用Git config—global credential保存了我的凭据。辅助存储。

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

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

nano ~/.git-credentials

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

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

git config --global credential.helper store

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

其他回答

在与这个问题斗争了差不多一整天之后,在ORG/REPO部分硬编码到我们的构建脚本中得到了可怕的“远程未找到”错误,最终我通过使用TRAVIS_REPO_SLUG找到了一个有效的解决方案。

将此转换为硬编码属性立即起作用。

git remote set-url origin https://[ORG]:${TOKEN}@github.com/${TRAVIS_REPO_SLUG}

通常我是这样做的:

 git push https://$(git_token)@github.com/user_name/repo_name.git

git_token是从Azure DevOps中的变量配置中读取的。

你可以在这里阅读我的完整博客文章。

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

唯一的答案,帮助我在一个VS Code环境和一个私人GitHub。

First =>在这里生成令牌:https://github.com/settings/tokens。 Second =>在VS Code终端的正确位置执行“cd”。 Third =>如下所示:

git克隆https://[MY_USER_NAME]:[GITHUB_PERSONAL_ACCESS_TOKEN]@github.com/davidsonlima/davidson-myrepo.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

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