PyGithub / PyGithub/PyGithub

Why is my repo object's master_branch property None?

Open
#3,007 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
7.8k
Forks
1.9k
Avg merge
17m
Merged PRs (30d)
2

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the Repository.master_branch entry point and compare its documented behavior with the GitHub API response for a private repository. Check the reported reproduction against the current library and API behavior; done means identifying whether the property or its usage needs correction and documenting a concrete resolution.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.