If you're iterating through a list of branches by name, it would be handy to be able to delete them directly:
# Example 1
repo.get_branch('feature-branch-1').delete()
# Example 2
for branch in repo.get_branches():
if some_condition:
branch.delete()
I think the only way currently available to delete branches is to call repo.get_git_ref()
to get a reference to the branch, and then call .delete()
on the returned object. What I'm proposing would complement this method.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
If you're iterating through a list of branches by name, it would be handy to be able to delete them directly:
# Example 1 repo.get_branch('feature-branch-1').delete() # Example 2 for branch in repo.get_branches(): if some_condition: branch.delete()
I think the only way currently available to delete branches is to call
repo.get_git_ref()
to get a reference to the branch, and then call.delete()
on the returned object. What I'm proposing would complement this method.
Please add this function, it will be very useful.
A quick workaround function to delete a branch, just in case its useful for anyone:
from github.GithubException import UnknownObjectException
def delete_branch(branch_name):
try:
ref = repo.get_git_ref(f"heads/{branch_name}")
ref.delete()
except UnknownObjectException:
print('No such branch', branch_name)
branch_name = "br-0004"
delete_branch(branch_name)
Most helpful comment
Please add this function, it will be very useful.