Last active
February 14, 2024 06:01
-
-
Save s1moe2/c08797f7e877040f0f693ff404d60d20 to your computer and use it in GitHub Desktop.
Clone private GitHub repo with go-git
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SSHClone clones a private GitHub repository using SSH, in the directory passed as parameter | |
func SSHClone(dest string) error { | |
var publicKey *ssh.PublicKeys | |
sshKey, err := ioutil.ReadFile("/Users/youruser/.ssh/id_rsa") | |
if err != nil { | |
return err | |
} | |
publicKey, err = ssh.NewPublicKeys("git", sshKey, "") | |
if err != nil { | |
return err | |
} | |
if _, err = git.PlainClone("/clone/destination/", false, &git.CloneOptions{ | |
URL: "[email protected]:theuser/therepo.git", | |
Auth: publicKey, | |
}); err != nil { | |
return err | |
} | |
return nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment