To those like me that want to call using a remote url without a local repo
import git
def _ls_remote_branches(url):
remote_branches = []
g = git.cmd.Git()
for ref in g.ls_remote(url).split("\n"):
if "head" in ref:
hash_ref_list = ref.split("\t")
remote_branches.append(
hash_ref_list[1].split("/")[-1]
)
return remote_branches
Edit 1: other answers did not work for me because I was looking for something that does not require a local git repo.
Edit 2: This was based on the upvoted answer to another question here