Skip to content
Discussion options

You must be logged in to vote

I believe I just answered this on stackoverflow but copy/pasting for posterity. (https://stackoverflow.com/questions/72038367/python-gitlab-unprotect-master)


You need to use the Protected Branches API (python-gitlab docs) for this.

protected_branch = project.protectedbranches.get("master")
protected_branch.delete()

# or simply
project.protectedbranches.delete("master")

Note: the delete() method in this case simply unprotects it, it does not delete the branch.

To re-protect it, you can then create it again. You can also control access levels directly:

protected_branch = project.protectedbranches.create({
    'name': 'master',
    'merge_access_level': gitlab.const.DEVELOPER_ACCESS,
    …

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@BlackWoxs
Comment options

Answer selected by nejch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants