Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set GitHub default branch through API call

Tags:

branch

github

api

I need to create a branch dev which is other than master branch. Also need to set dev as default branch using GITHUB API.

Please share details if anyone know which API to call or a way to do it, programmatically. I know that it can be done through the Web UI, however I am looking for a solution that does not involve manual intervention.

like image 953
Ashish Bhatia Avatar asked Oct 12 '18 09:10

Ashish Bhatia


People also ask

How do I change the default branch of a GitHub repository?

On GitHub.com, navigate to the main page of the repository. Under your repository name, click Settings . In the "Code and automation" section of the sidebar, click Branches. Under "Default branch", to the right of the default branch name, click . Use the drop-down, then click a branch name.

What's the difference between the REST API and branches API?

We've recently moved some of the REST API documentation. If you can't find what you're looking for, you might try the new Commits, Deploy Keys, Deployments, GitHub Pages, Releases, Metrics, Webhooks REST API pages. The branches API allows you to modify branches and their protection settings.

How do I change the default branch name?

In the "Code and automation" section of the sidebar, click Branches. Under "Default branch", to the right of the default branch name, click . Use the drop-down, then click a branch name. Click Update . Read the warning, then click I understand, update the default branch.


Video Answer


1 Answers

I don't have enough reputation to reply to the Adam's comment above but the problem is name is a required field. The JSON should actually be:

PATCH /repos/:owner/:repo
{
"name":":repo"
"default_branch": "dev"
}
like image 94
user3147860 Avatar answered Oct 01 '22 11:10

user3147860