PyGithub icon indicating copy to clipboard operation
PyGithub copied to clipboard

Why is my repo object's master_branch property None?

Open zhighleggett opened this issue 1 year ago • 2 comments

Hello,

I'm trying to programatically get the name of the master branch of my repo. To do this I'm trying to access the master_branch property in Repository but even though the documentation says it should return a string, I get back None regardless of the repo I've checked.

The repos are all private work-related repos so I can't share the exact code here but basically what I'm doing is:

>>> import github
>>> gh = github.Github("ACCESS_TOKEN_REDACTED")
>>> org = gh.get_organization("ORG_NAME_REDACTED")
>>> repo = org.get_repo("REPO_NAME_REDACTED")
>>> branch = repo.master_branch
>>> branch is None
True

Does this suggest I've configured my repo incorrectly? Or am I misunderstanding how to properly use the library?

Thanks in advance. Please let me know what other information might be helpful for troubleshooting.

zhighleggett avatar Jul 26 '24 22:07 zhighleggett

I get the same kind of error when trying to access any property! Applies to delete_branch_on_merge, allow_merge_commit, etc. They are all None.

It appears that the _completeIfNotSet method doesn't work correctly?

kkom avatar Oct 02 '24 17:10 kkom

@kkom I never did figure out why master_branch wasn't set and I don't know if it'll help with the other attributes you're looking for but repo.default_branch ended up working to get the master branch name.

zhighleggett avatar Oct 02 '24 17:10 zhighleggett