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

这对我很有用。

其他回答

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

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

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

克隆你的项目-> git克隆https://token@github.com//project.git 在项目文件夹-> git配置-global credential。辅助缓存

和工作

如果你正在使用GitHub企业,克隆存储库或推送给你一个403错误,而不是提示输入用户名/令牌,你可以使用这个:

删除存储库 打开命令提示符并导航到您希望存储库所在的文件夹 类型: git克隆https://[USERNAME]:[TOKEN]@[GIT_ENTERPRISE_DOMAIN]/[ORGANIZATION]/[REPO].git

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

通常我是这样做的:

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

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

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