79525220

Date: 2025-03-21 10:47:32
Score: 2
Natty:
Report link

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

Reasons:
  • Blacklisted phrase (1): another question
  • Blacklisted phrase (1): did not work
  • Blacklisted phrase (0.5): upvote
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: Chubs