github-api

How do I find the default branch for a repository using the Github v3 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?


Solution

  • 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