Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I find the default branch for a repository using the Github v3 API

Tags:

github-api

My goal is to get the tree for the latest SHA in the default branch

GET /repos/:owner/:repo/git/trees/:sha

How do I find the lastest SHA from the default branch?

I know that I can call

GET /repos/:owner/:repo/branches/:branch

But I can't just use "master" for the branch as not all repos use master as the default branch.

How do I find out what the default branch for a repo is?

like image 416
Daniel X Moore Avatar asked May 11 '13 18:05

Daniel X Moore


People also ask

What is the default branch of a GitHub repository?

Unless you specify a different branch, the default branch in a repository is the base branch for new pull requests and code commits. By default, GitHub names the default branch main in any new repository. You can change the default branch for an existing repository.

What is the default branch in local repository?

The default branch name in Git is master .

What is the default branch of a GitHub repository 1 Master 2 Main 3 Home 4 demo?

The default branch name for new repositories is now main . To set a different default: For users, on the https://github.com/settings/repositories page. For organization owners, on the https://github.com/organizations/YOUR-ORGANIZATION/settings/repository-defaults page.


1 Answers

Make a call to /repos/:owner/:repo and read the default_branch property value - this is the name of the default branch. See example response here: http://developer.github.com/v3/repos/#get

like image 171
Ivan Zuzak Avatar answered Sep 23 '22 20:09

Ivan Zuzak