I want a list of all the remote branches for a git repo. Now, this git repo can be private / public. I have the access to the token to access the repo.
I am using this particular SDK : https://pkg.go.dev/github.com/go-git/go-git/v5
One way to do this is ..
r, cloneErr := git.PlainClone(projectRoot, false, cloneOptions)
remote, err := r.Remote("origin")
if err != nil {
panic(err)
}
refList, err := remote.List(&git.ListOptions{})
if err != nil {
panic(err)
}
refPrefix := "refs/heads/"
for _, ref := range refList {
refName := ref.Name().String()
if !strings.HasPrefix(refName, refPrefix) {
continue
}
branchName := refName[len(refPrefix):]
fmt.Println(branchName)
}
But, this involves cloning the repo first. How can I get the list without cloning the repo ?
Thanks in advence !