Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Manipulate Branches of a Repository Using GitHub REST APIs

Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!

from github_rest_api.github import Repository
from github_rest_api.utils import strip_patch_version
repo = Repository(token="", repo="legendu-net/docker-rust-cicd")
repo
<github_rest_api.github.Repository at 0x7fda4c157e00>
repo.get_branches()
[{'name': 'dev', 'commit': {'sha': 'b4666bd451cf78711a8d6b8c6aff7cb9b410c911', 'url': 'https://api.github.com/repos/legendu-net/docker-rust-cicd/commits/b4666bd451cf78711a8d6b8c6aff7cb9b410c911'}, 'protected': False}, {'name': 'main', 'commit': {'sha': 'f3debc34905c1734ed269aea2a425e11ef72851e', 'url': 'https://api.github.com/repos/legendu-net/docker-rust-cicd/commits/f3debc34905c1734ed269aea2a425e11ef72851e'}, 'protected': True}]
repo.delete_ref?
Signature: repo.delete_ref(ref: str) -> None Docstring: Delete a reference from this repository. :param ref: The reference to delete from this repository. File: ~/.local/lib/python3.10/site-packages/github_rest_api/github.py Type: method
repo.delete_branch?
Signature: repo.delete_branch(branch: str) -> None Docstring: Delete a branch from this repository. :param branch: The branch to delete from this repository. File: ~/.local/lib/python3.10/site-packages/github_rest_api/github.py Type: method