src-d / go-git

Project has been moved to: https://github.com/go-git/go-git
https://github.com/go-git/go-git
Apache License 2.0
4.91k stars 541 forks source link

Clone Git using SSH ( SOLVED ) #1228

Closed supanadit closed 4 years ago

supanadit commented 4 years ago

This is how i work

url := "git@github.com:supanadit/gostay.git"
var publicKey *ssh.PublicKeys
sshPath := os.Getenv("HOME") + "/.ssh/id_rsa"
sshKey, _ := ioutil.ReadFile(sshPath)
publicKey, keyError := ssh.NewPublicKeys("git", []byte(sshKey), "")
if keyError != nil {
    fmt.Println(keyError)
}
_, err := git.PlainClone(url, false, &git.CloneOptions{
    URL:      urlGitConversion,
    Progress: os.Stdout,
    Auth:     publicKey,
})

Originally posted by @supanadit in https://github.com/src-d/go-git/issues/550#issuecomment-543013929