pythonpygithub

PyGithub - Can't set attribute error while trying to change default branch


I've written this code to change the default branch from "master" to "release".

from github import Github
g = Github("github token", verify=False, base_url="url to repo")

repo = g.get_repo("repo name")
repo.default_branch = 'release'

I am getting the following error.

   repo.default_branch = 'release'
AttributeError: can't set attribute

I am the admin of that repository and I created the branch. I don't think this is an access issue. What am I doing incorrectly?


Solution

  • The default_branch attribute is a read-only attribute; if you want to change the default branch you need to use the edit method:

    repo.edit(default_branch='release')