pygithub

How to get the default branch in PyGithub?


I was looking through the PyGithub documentation https://pygithub.readthedocs.io/en/latest/introduction.html but I can't find any function that returns the default branch.

In the examples, "main" is used but "main" is not always the default. It could be "master" or some other user specified branch.

Just wondering if there's a way to do this with PyGithub.


Solution

  • (Just met the same problem.)

    The Repository class has a default_branch property, which is available after you get_repo.

    from github import Github
    
    
    repo = Github().get_repo('PyGithub/PyGithub')
    print(repo.default_branch)
    
    #=> main