Get repository content

GET {{baseUrl}}/repos/:owner/:repo/contents/:path?ref=<string>

Gets the contents of a file or directory in a repository. Specify the file path or directory in :path. If you omit :path, you will receive the contents of all files in the repository.

Files and symlinks support a custom media type for retrieving the raw content or rendered HTML (when supported). All content types support a custom media type to ensure the content is returned in a consistent object format.

Note: * To get a repository's contents recursively, you can recursively get the tree. * This API has an upper limit of 1,000 files for a directory. If you need to retrieve more files, use the Git Trees API. * This API supports files up to 1 megabyte in size.

If the content is a directory

The response will be an array of objects, one object for each item in the directory. When listing the contents of a directory, submodules have their type specified as file. Logically, the value should be submodule. This behavior exists in API v3 for backwards compatibility purposes. In the next major version of the API, the type will be returned as submodule.

If the requested :path points to a symlink, and the symlink's target is a normal file in the repository, then the API responds with the content of the file (in the format shown in the example. Otherwise, the API responds with an object describing the symlink itself.

If the content is a submodule

The submodule_git_url identifies the location of the submodule repository, and the sha identifies a specific commit within the submodule repository. Git uses the given URL when cloning the submodule repository, and checks out the submodule at that specific commit.

If the submodule repository is not hosted on github.com, the Git URLs (git_url and _links["git"]) and the github.com URLs (html_url and _links["html"]) will have null values.

Request Params

KeyDatatypeRequiredDescription
refstringThe name of the commit/branch/tag. Default: the repository’s default branch (usually master)

RESPONSES

status: OK

{&quot;type&quot;:&quot;file&quot;,&quot;encoding&quot;:&quot;base64&quot;,&quot;size&quot;:5362,&quot;name&quot;:&quot;README.md&quot;,&quot;path&quot;:&quot;README.md&quot;,&quot;content&quot;:&quot;encoded content ...&quot;,&quot;sha&quot;:&quot;3d21ec53a331a6f037a91c368710b99387d012c1&quot;,&quot;url&quot;:&quot;https://api.github.com/repos/octokit/octokit.rb/contents/README.md&quot;,&quot;git_url&quot;:&quot;https://api.github.com/repos/octokit/octokit.rb/git/blobs/3d21ec53a331a6f037a91c368710b99387d012c1&quot;,&quot;html_url&quot;:&quot;https://github.com/octokit/octokit.rb/blob/master/README.md&quot;,&quot;download_url&quot;:&quot;https://raw.githubusercontent.com/octokit/octokit.rb/master/README.md&quot;,&quot;_links&quot;:{&quot;git&quot;:&quot;https://api.github.com/repos/octokit/octokit.rb/git/blobs/3d21ec53a331a6f037a91c368710b99387d012c1&quot;,&quot;self&quot;:&quot;https://api.github.com/repos/octokit/octokit.rb/contents/README.md&quot;,&quot;html&quot;:&quot;https://github.com/octokit/octokit.rb/blob/master/README.md&quot;}}