Xiaowen Zhang
Xiaowen Zhang

Reputation: 169

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

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?

Upvotes: 1

Views: 259

Answers (1)

VonC
VonC

Reputation: 1329262

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"

Upvotes: 1

Related Questions