HTTP.Auth at pull and push
Hi,
I am trying to pull and push a project of mine with your library. When I try to pull it, I get "authentication required". I can't seem to figure out how to put my credentials into the library.
func gitPull() {
r, err := git.PlainOpen(path)
if err != nil {
log.Fatal(err.Error())
}
w, err := r.Worktree()
if err != nil {
log.Fatal(err.Error())
}
err = w.Pull(&git.PullOptions{RemoteName:"origin"})
if err != nil {
log.Fatal(err.Error())
}
}
@cooperspencer Did you manage to get a solution?
Yes, I did. Thank you for asking.
@cooperspencer Could you possibly share the solution? I also am new to Golang and am unable to pull over http/https
"git pull origin error: authentication required"
@bugul-noz sure thing.
func gitPull(repo string, user string, password string) {
auth := &githttp.BasicAuth{user, password}
r, err := git.PlainOpen(repo)
if err != nil {
log.Fatal(err.Error())
}
w, err := r.Worktree()
if err != nil {
log.Fatal(err.Error())
}
err = w.Pull(&git.PullOptions{RemoteName:"origin", Auth:auth})
fmt.Println(err)
}
@cooperspencer Thank you! I really appreciate it.