使用 git OAuth 令牌克隆 Repo

Use git OAuth token to clone the Repo

我正在使用给定的 golang 代码克隆 public gitrepo:(工作正常)

_, err = git.PlainClone(projectRoot, false, &git.CloneOptions{
    URL:      e.Repo,
    Progress: os.Stdout,
})

对于私有 git 存储库,我正在生成一个 OAuth 令牌和下面给出的代码:

_, err = git.PlainClone(projectRoot, false, &git.CloneOptions{
    Auth:     &gitHttp.TokenAuth{Token: <oauth-token>},
    URL:      e.Repo,
    Progress: os.Stdout,
})

这给了我类似的东西:

unexpected client error: unexpected requesting "https://github.com/.../info/refs?service=git-upload-pack" status code: 400

我正在使用这些特定的模块

git "github.com/go-git/go-git/v5"
gitHttp "github.com/go-git/go-git/v5/plumbing/transport/http"
_, err = git.PlainClone(projectRoot, false, &git.CloneOptions{
    Auth:     &gitHttp.BasicAuth{Username: <username>, Password: <oauth-token>},
    URL:      e.Repo,
    Progress: os.Stdout,
})