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


当前回答

唯一的答案,帮助我在一个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不带方括号

其他回答

通常我是这样做的:

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

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

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

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

删除当前原点:

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

Windows:

打开凭证管理器- Windows凭证 找到git的条目:https://github.com,编辑它 用PAT访问令牌替换以前的密码 解决了

生成令牌

使用创建个人访问令牌中的说明生成令牌。 (GitHub配置文件->设置->开发者设置->个人访问令牌)

实际上使用令牌

如果您已经在本地克隆了存储库

git remote remove origin
git remote add origin https://[TOKEN]@github.com/[REPO-OWNER]/[REPO-NAME]
git push

如果您正在克隆一个新的存储库

git clone https://[TOKEN]@github.com/[REPO-OWNER]/[REPO-NAME]

(将方括号和方括号之间的内容替换为相应的详细信息。@后面的部分与不带https://)的存储库url相同