go-git icon indicating copy to clipboard operation
go-git copied to clipboard

HTTP.Auth at pull and push

Open cooperspencer opened this issue 8 years ago • 5 comments

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 avatar Jul 16 '18 09:07 cooperspencer

@cooperspencer Did you manage to get a solution?

smola avatar Jul 24 '18 10:07 smola

Yes, I did. Thank you for asking.

cooperspencer avatar Jul 25 '18 06:07 cooperspencer

@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"

Grey-Wulver avatar Aug 03 '18 16:08 Grey-Wulver

@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 avatar Aug 04 '18 06:08 cooperspencer

@cooperspencer Thank you! I really appreciate it.

Grey-Wulver avatar Aug 05 '18 14:08 Grey-Wulver