I know there is an API for getting repository content. But my use case is I need to get the whole repository and display it in my UI like GitHub UI. Similar to GitHub UI, I need my repository to be displayed in my UI. Is there any API I can use to get the whole repository so I can display that in my UI.
I tried this API.
curl \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer <YOUR-TOKEN>" \
https://api.github.com/repos/OWNER/REPO/zipball/REF
But it gives separate file contents. I need the whole repo.
Nov. 2022: Getting the all repository remains easier with a simple git clone. No need for an API call there.
If, as mentioned in this 2016 octokit issue, you cannot clone through GitHub API, you could use libgit2sharp to integrate the clone operation in your application.
Dec. 2025 update:
Back in 2022, my answer focused on git clone which is still the simplest way to get a full working copy if you control the environment.
my use case is I need to get the whole repository and display it in my UI like GitHub UI.
For that, the /zipball endpoint you tried is not ideal. It returns a binary archive of the repo at a given ref (branch, tag, or commit). It is great for downloads, but to render a tree view you would have to:
For a GitHub-like browser it is more convenient to query the Git database directly and receive a JSON representation of the tree. (using the GitHub API)
I tried (on Windows, in a CMD, so replace the double quotes with single quotes for the jq parts if you run this in a Unix shell):
curl -s -H "Accept: application/vnd.github+json" https://api.github.com/repos/VonC/batcolors | jq -r ".default_branch"
curl -H "Accept: application/vnd.github+json" https://api.github.com/repos/VonC/batcolors/branches/legacy | jq -r ".commit.commit.tree.sha"
curl -H "Accept: application/vnd.github+json" https://api.github.com/repos/VonC/batcolors/git/trees/443e4eb34b21322fb7f61dd67169de614b0823f0?recursive=1 | jq ".tree[] | {path: .path, type: .type}"
You can also use the GitHub CLI with the gh api command to do the same (no need for jq to be installed if you use its gh api --jq option):
gh api repos/VonC/batcolors --jq ".default_branch"
gh api repos/VonC/batcolors/branches/legacy --jq ".commit.commit.tree.sha"
gh api "repos/VonC/batcolors/git/trees/443e4eb34b21322fb7f61dd67169de614b0823f0?recursive=1" --jq ".tree[] | {path, type, size}"
Result:
{
"path": ".gitattributes",
"type": "blob",
"size": 21
}
{
"path": ".gitignore",
"type": "blob",
"size": 11
}
{
"path": ".vscode",
"type": "tree",
"size": null
}
{
"path": ".vscode/batcolors.code-workspace",
"type": "blob",
"size": 906
}
...
Then you can use a project like Pomax/custom-file-tree (with demo here), or, in the react world, brimdata/react-arborist to render that JSON (after a bit of post-processing to fit the expected format) in a tree view in your own web UI.