我正在尝试使用个人访问令牌与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 push https://$(git_token)@github.com/user_name/repo_name.git

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

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

其他回答

通过在应用GitHub令牌上挣扎了这么多小时,最终它的工作原理如下:

$ cf_export GITHUB_TOKEN=$(codefresh get context github——decryph -o . Yaml | yq -y .spec.data.auth.password)

代码遵循Codefresh关于使用令牌克隆回购的指导(freestyle} 测试进行:sed %d%H%M匹配词'-123456-whatever' 推回回购(私人回购) 由DockerHub webhooks触发

以下是完整的代码:

version: '1.0'
steps:
  get_git_token:
    title: Reading Github token
    image: codefresh/cli
    commands:
      - cf_export GITHUB_TOKEN=$(codefresh get context github --decrypt -o yaml | yq -y .spec.data.auth.password)
  main_clone:
    title: Updating the repo
    image: alpine/git:latest
    commands:
      - git clone https://chetabahana:$GITHUB_TOKEN@github.com/chetabahana/compose.git
      - cd compose && git remote rm origin
      - git config --global user.name "chetabahana"
      - git config --global user.email "chetabahana@gmail.com"
      - git remote add origin https://chetabahana:$GITHUB_TOKEN@github.com/chetabahana/compose.git
      - sed -i "s/-[0-9]\{1,\}-\([a-zA-Z0-9_]*\)'/-`date +%d%H%M`-whatever'/g" cloudbuild.yaml
      - git status && git add . && git commit -m "fresh commit" && git push -u origin master

输出……

On branch master 
Changes not staged for commit: 
  (use "git add ..." to update what will be committed) 
  (use "git checkout -- ..." to discard changes in working directory) 

modified:   cloudbuild.yaml 

no changes added to commit (use "git add" and/or "git commit -a") 
[master dbab20f] fresh commit 
 1 file changed, 1 insertion(+), 1 deletion(-) 
Enumerating objects: 5, done. 
Counting objects:  20% (1/5) ...  Counting objects: 100% (5/5), done. 
Delta compression using up to 4 threads 
Compressing objects:  33% (1/3) ... Writing objects: 100% (3/3), 283 bytes | 283.00 KiB/s, done. 
Total 3 (delta 2), reused 0 (delta 0) 
remote: Resolving deltas:   0% (0/2)  ...   (2/2), completed with 2 local objects. 
To https://github.com/chetabahana/compose.git 
   bbb6d2f..dbab20f  master -> master 
Branch 'master' set up to track remote branch 'master' from 'origin'. 
Reading environment variable exporting file contents. 
Successfully ran freestyle step: Cloning the repo 

从开发人员设置生成访问令牌后,运行这些命令, 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中的变量配置中读取的。

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

步骤1:获取访问令牌

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

步骤2:使用令牌

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

最近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

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