Keval Bhogayata
Keval Bhogayata

Reputation: 6676

Use git OAuth token to clone the Repo

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"

Upvotes: 0

Views: 980

Answers (1)

Keval Bhogayata
Keval Bhogayata

Reputation: 6676

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

Upvotes: 2

Related Questions