How to list files of the default branch for a repository using the Github API via one query?

Viewed 66

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

Different from the related problem, I want to list the files of the default branch.

The API I know to list files of the master branch is:

https://api.github.com/repos/owner/repo_name/git/trees/master

However, the default branch name could be main.

Is there a way to list files of the default branch through only one query?

1 Answers

You could use HEAD simply (which refers to the default remote branch).

I tried it using gh api after a (gh auth login)

gh api repos/owner/repo_name/git/trees/HEAD

Example:

gh api repos/VonC/gitcred/git/trees/HEAD --jq ".tree[].path"
Related