Home > database >  Use git OAuth token to clone the Repo
Use git OAuth token to clone the Repo

Time:10-15

I am cloning public gitrepo with given golang code: (which works fine)

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

For the private git repo, I am generating an OAuth token and the code given below:

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

This is giving me something like :

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

I am using these particular modules

git "github.com/go-git/go-git/v5"
gitHttp "github.com/go-git/go-git/v5/plumbing/transport/http"

CodePudding user response:

_, err = git.PlainClone(projectRoot, false, &git.CloneOptions{
    Auth:     &gitHttp.BasicAuth{Username: <username>, Password: <oauth-token>},
    URL:      e.Repo,
    Progress: os.Stdout,
})
  • Related