Skip to content

Instantly share code, notes, and snippets.

@roscopecoltran
Forked from arehmandev/main.go
Created November 16, 2018 00:18
Show Gist options
  • Save roscopecoltran/84d00d5c5c9b50643220f92c43b4c536 to your computer and use it in GitHub Desktop.
Save roscopecoltran/84d00d5c5c9b50643220f92c43b4c536 to your computer and use it in GitHub Desktop.
Doing a git clone of a tag in Go - the easy way
package main
import (
"log"
"gopkg.in/src-d/go-git.v4/plumbing"
"gopkg.in/src-d/go-git.v4"
)
// Basic example of how to clone a repository using clone options.
func main() {
url := "https://github.com/arehmandev/pochelm.git"
directory := "pochelm"
tag := "v0.2.0"
gitclonetag(url, directory, tag)
}
func gitclonetag(repourl, directory, tag string) {
y := plumbing.ReferenceName(tag)
// Clone the given repository to the given directory, you can also clone branches via ReferenceName: "refs/heads/branchname"
_, err := git.PlainClone(directory, false, &git.CloneOptions{
URL: repourl,
ReferenceName: "refs/tags/" + y,
SingleBranch: true,
RecurseSubmodules: git.DefaultSubmoduleRecursionDepth,
})
if err != nil {
log.Fatal(err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment