import subprocess def list_all_tags_for_remote_git_repo(url): """ Given a repository URL, list all tags for that repository without cloning it. This function use "git ls-remote", so the "git" command line program must be available. """ # Run the 'git' command to fetch and list remote tags result = subprocess.run([ "git", "ls-remote", "--tags", repo_url ], stdout=subprocess.PIPE, text=True) # Process the output to extract tag names output_lines = result.stdout.splitlines() tags = [ line.split("refs/tags/")[-1] for line in output_lines if "refs/tags/" in line and "^{}" not in line ] return tags
Usage example:
list_all_tags_for_remote_git_repo("https://github.com/EmbeddedRPC/erpc.git")
Result:
['1.10.0', '1.11.0', '1.4.0', '1.4.1', '1.5.0', '1.6.0', '1.7.0', '1.7.1', '1.7.2', '1.7.3', '1.7.4', '1.8.0', '1.8.1', '1.9.0', '1.9.1']