GitHub – How to Set Git Branch Protected by Default When Created

automationgithub

I need to make a branch protected directly when creating it. I know that I need to go to Settings and set it as protected from there, but what I'm looking for is to set the branch as protected automatically without the need to do that.

Best Answer

GitHub doesn't have a way to natively enable branch protection for new branches. However, you could set up an automated process using "Update branch protection" from the GitHub API to add branch protection to all new branches.

PUT /repos/:owner/:repo/branches/:branch/protection