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.

Get Branch Info Using GitHub Rest API

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

from github_rest_api import Repository
repo = Repository(token="", repo="legendu-net/docker")
repo
<github_rest_api.github.Repository at 0x7fd5dc6b27b0>
branches = repo.get_branches()
branches[0]
{'name': 'coder_code-server_version_20260421', 'commit': {'sha': '2de5c6ee14a0f72f0e3bcebabee35b1a0c49c5da', 'url': 'https://api.github.com/repos/legendu-net/docker/commits/2de5c6ee14a0f72f0e3bcebabee35b1a0c49c5da'}, 'protected': False}
br = repo.get_branch(branches[0]["name"])
br
{'name': 'coder_code-server_version_20260421', 'commit': {'sha': '2de5c6ee14a0f72f0e3bcebabee35b1a0c49c5da', 'node_id': 'C_kwDORBZ3XdoAKDJkZTVjNmVlMTRhMGY3MmYwZTNiY2ViYWJlZTM1YjFhMGM0OWM1ZGE', 'commit': {'author': {'name': 'Ben Du', 'email': 'longendu@yahoo.com', 'date': '2026-04-21T04:22:44Z'}, 'committer': {'name': 'Ben Du', 'email': 'longendu@yahoo.com', 'date': '2026-04-21T04:22:44Z'}, 'message': 'install deno & jupyter kernel for deno', 'tree': {'sha': 'e18ae8408f35e52496d16c0ec7e573faf6712182', 'url': 'https://api.github.com/repos/legendu-net/docker/git/trees/e18ae8408f35e52496d16c0ec7e573faf6712182'}, 'url': 'https://api.github.com/repos/legendu-net/docker/git/commits/2de5c6ee14a0f72f0e3bcebabee35b1a0c49c5da', 'comment_count': 0, 'verification': {'verified': False, 'reason': 'unsigned', 'signature': None, 'payload': None, 'verified_at': None}}, 'url': 'https://api.github.com/repos/legendu-net/docker/commits/2de5c6ee14a0f72f0e3bcebabee35b1a0c49c5da', 'html_url': 'https://github.com/legendu-net/docker/commit/2de5c6ee14a0f72f0e3bcebabee35b1a0c49c5da', 'comments_url': 'https://api.github.com/repos/legendu-net/docker/commits/2de5c6ee14a0f72f0e3bcebabee35b1a0c49c5da/comments', 'author': None, 'committer': None, 'parents': [{'sha': 'b3afee3d64ad2b97563e7e0eedc43cdc51f714b3', 'url': 'https://api.github.com/repos/legendu-net/docker/commits/b3afee3d64ad2b97563e7e0eedc43cdc51f714b3', 'html_url': 'https://github.com/legendu-net/docker/commit/b3afee3d64ad2b97563e7e0eedc43cdc51f714b3'}]}, '_links': {'self': 'https://api.github.com/repos/legendu-net/docker/branches/coder_code-server_version_20260421', 'html': 'https://github.com/legendu-net/docker/tree/coder_code-server_version_20260421'}, 'protected': False, 'protection': {'enabled': False, 'required_status_checks': {'enforcement_level': 'off', 'contexts': [], 'checks': []}}, 'protection_url': 'https://api.github.com/repos/legendu-net/docker/branches/coder_code-server_version_20260421/protection'}
br.get("created_at") or br.get("commit", {}).get("commit", {}).get("committer", {}).get("date")
'2026-04-21T04:22:44Z'
br.get("commit")
{'sha': '2de5c6ee14a0f72f0e3bcebabee35b1a0c49c5da', 'node_id': 'C_kwDORBZ3XdoAKDJkZTVjNmVlMTRhMGY3MmYwZTNiY2ViYWJlZTM1YjFhMGM0OWM1ZGE', 'commit': {'author': {'name': 'Ben Du', 'email': 'longendu@yahoo.com', 'date': '2026-04-21T04:22:44Z'}, 'committer': {'name': 'Ben Du', 'email': 'longendu@yahoo.com', 'date': '2026-04-21T04:22:44Z'}, 'message': 'install deno & jupyter kernel for deno', 'tree': {'sha': 'e18ae8408f35e52496d16c0ec7e573faf6712182', 'url': 'https://api.github.com/repos/legendu-net/docker/git/trees/e18ae8408f35e52496d16c0ec7e573faf6712182'}, 'url': 'https://api.github.com/repos/legendu-net/docker/git/commits/2de5c6ee14a0f72f0e3bcebabee35b1a0c49c5da', 'comment_count': 0, 'verification': {'verified': False, 'reason': 'unsigned', 'signature': None, 'payload': None, 'verified_at': None}}, 'url': 'https://api.github.com/repos/legendu-net/docker/commits/2de5c6ee14a0f72f0e3bcebabee35b1a0c49c5da', 'html_url': 'https://github.com/legendu-net/docker/commit/2de5c6ee14a0f72f0e3bcebabee35b1a0c49c5da', 'comments_url': 'https://api.github.com/repos/legendu-net/docker/commits/2de5c6ee14a0f72f0e3bcebabee35b1a0c49c5da/comments', 'author': None, 'committer': None, 'parents': [{'sha': 'b3afee3d64ad2b97563e7e0eedc43cdc51f714b3', 'url': 'https://api.github.com/repos/legendu-net/docker/commits/b3afee3d64ad2b97563e7e0eedc43cdc51f714b3', 'html_url': 'https://github.com/legendu-net/docker/commit/b3afee3d64ad2b97563e7e0eedc43cdc51f714b3'}]}