How Do You Find Out if a GitHub Repository’s Branch is Protected or Not?

Problem scenario
Using the API you want to know if a given GitHub repository's branch is protected. What do you do?

Solution
Draft the four commands below. Replace "jdoe" with the GitHub username. Replace "organizationname" with the organization name in your repo. Replace "repositoryname" with the repository name. Replace "master" with the branch you want to check. Then run the four commands below. You will be prompted to enter a password.

ORGNAME=organizationname
REPONAME=repositoryname
BRANCHNAME=master
curl -u jdoe https://api.github.com/repos/$ORGNAME/$REPONAME/branches/$BRANCHNAME/protection

Leave a comment

Your email address will not be published. Required fields are marked *