Esta versión de GitHub Enterprise se discontinuó el 2022-06-03. No se realizarán lanzamientos de patch, ni siquiera para problemas de seguridad críticos. Para obtener un mejor desempeño, más seguridad y nuevas características, actualiza a la última versión de GitHub Enterprise. Para obtener ayuda con la actualización, contacta al soporte de GitHub Enterprise.
We've recently moved some of the REST API documentation. If you can't find what you're looking for, you might try the new Branches, Collaborators, Commits, Deploy Keys, Deployments, GitHub Pages, Releases, Metrics, Webhooks REST API pages.
Contenidos del repositorio
Las terminales de esta API te permiten crear, modificar y borrar contenido cifrado en Base64 en un repositorio.
About the Repository contents API
Para solicitar el formato sin procesar y interpretado en HTML (cuando sea posible), utiliza los tipos de medios personalizados para el contenido de un repositorio.
Tipos de medios personalizados para el contenido de un repositorio
Los README, archivos y symlinks son compatibles con los siguientes tipos de medios personalizados:
application/vnd.github.VERSION.raw
application/vnd.github.VERSION.html
Utiliza el tipo de medios .raw
para recuperar el contenido del archivo.
Para archivos de markup tales como Markdown o AsciiDoc, puedes recuperar la interpretación en HTML si utilizas el tipo de medios .html
. Los lenguajes de Markup se interpretan en HTML utilizando nuestra biblioteca de Markup de código abierto.
Todos los objetos son compatibles con el siguiente tipo de medios personalizados:
application/vnd.github.VERSION.object
Utiliza el parámetro de tipo de medios object
para recuperar el contenido en un formato de objeto consistente sin importar el tipo de contenido. Por ejemplo, en vez de ser una matriz de objetos para un directorio, la respuesta será un objeto con un atributo de entries
que contenga la matriz de objetos.
Puedes leer más acerca del uso de tipos de medios en la API aquí.
Get repository content
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 the repository's root directory. See the description below regarding what the API response includes for directories.
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 content is a symlink
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.
Parámetros
Encabezados |
---|
Nombre, Tipo, Descripción |
accept stringSetting to |
Parámetros de ruta |
Nombre, Tipo, Descripción |
owner stringRequeridoThe account owner of the repository. The name is not case sensitive. |
repo stringRequeridoThe name of the repository. The name is not case sensitive. |
path stringRequeridopath parameter |
Parámetros de consulta |
Nombre, Tipo, Descripción |
ref stringThe name of the commit/branch/tag. Default: the repository’s default branch (usually |
Códigos de estado de respuesta HTTP
Código de estado | Descripción |
---|---|
200 | OK |
302 | Found |
403 | Forbidden |
404 | Resource not found |
Ejemplos de código
curl \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: token <TOKEN>" \
http(s)://HOSTNAME/api/v3/repos/OWNER/REPO/contents/PATH
Response if content is a file
Status: 200
{
"type": "file",
"encoding": "base64",
"size": 5362,
"name": "README.md",
"path": "README.md",
"content": "encoded content ...",
"sha": "3d21ec53a331a6f037a91c368710b99387d012c1",
"url": "https://api.github.com/repos/octokit/octokit.rb/contents/README.md",
"git_url": "https://api.github.com/repos/octokit/octokit.rb/git/blobs/3d21ec53a331a6f037a91c368710b99387d012c1",
"html_url": "https://github.com/octokit/octokit.rb/blob/master/README.md",
"download_url": "https://raw.githubusercontent.com/octokit/octokit.rb/master/README.md",
"_links": {
"git": "https://api.github.com/repos/octokit/octokit.rb/git/blobs/3d21ec53a331a6f037a91c368710b99387d012c1",
"self": "https://api.github.com/repos/octokit/octokit.rb/contents/README.md",
"html": "https://github.com/octokit/octokit.rb/blob/master/README.md"
}
}
Create or update file contents
Creates a new file or replaces an existing file in a repository.
Parámetros
Encabezados | |||||||
---|---|---|---|---|---|---|---|
Nombre, Tipo, Descripción | |||||||
accept stringSetting to | |||||||
Parámetros de ruta | |||||||
Nombre, Tipo, Descripción | |||||||
owner stringRequeridoThe account owner of the repository. The name is not case sensitive. | |||||||
repo stringRequeridoThe name of the repository. The name is not case sensitive. | |||||||
path stringRequeridopath parameter | |||||||
Parámetros de cuerpo | |||||||
Nombre, Tipo, Descripción | |||||||
message stringRequeridoThe commit message. | |||||||
content stringRequeridoThe new file content, using Base64 encoding. | |||||||
sha stringRequired if you are updating a file. The blob SHA of the file being replaced. | |||||||
branch stringThe branch name. Default: the repository’s default branch (usually | |||||||
committer objectThe person that committed the file. Default: the authenticated user. | |||||||
Properties of the |
Nombre, Tipo, Descripción |
---|
name stringRequeridoThe name of the author or committer of the commit. You'll receive a |
email stringRequeridoThe email of the author or committer of the commit. You'll receive a |
date string |
author
objectThe author of the file. Default: The committer
or the authenticated user if you omit committer
.
Properties of theauthor
object
Nombre, Tipo, Descripción |
---|
name stringRequeridoThe name of the author or committer of the commit. You'll receive a |
email stringRequeridoThe email of the author or committer of the commit. You'll receive a |
date string |
Códigos de estado de respuesta HTTP
Código de estado | Descripción |
---|---|
200 | OK |
201 | Created |
404 | Resource not found |
409 | Conflict |
422 | Validation failed |
Ejemplos de código
curl \
-X PUT \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: token <TOKEN>" \
http(s)://HOSTNAME/api/v3/repos/OWNER/REPO/contents/PATH \
-d '{"message":"my commit message","committer":{"name":"Monalisa Octocat","email":"octocat@github.com"},"content":"bXkgbmV3IGZpbGUgY29udGVudHM="}'
Response
Status: 201
{
"content": {
"name": "hello.txt",
"path": "notes/hello.txt",
"sha": "95b966ae1c166bd92f8ae7d1c313e738c731dfc3",
"size": 9,
"url": "https://api.github.com/repos/octocat/Hello-World/contents/notes/hello.txt",
"html_url": "https://github.com/octocat/Hello-World/blob/master/notes/hello.txt",
"git_url": "https://api.github.com/repos/octocat/Hello-World/git/blobs/95b966ae1c166bd92f8ae7d1c313e738c731dfc3",
"download_url": "https://raw.githubusercontent.com/octocat/HelloWorld/master/notes/hello.txt",
"type": "file",
"_links": {
"self": "https://api.github.com/repos/octocat/Hello-World/contents/notes/hello.txt",
"git": "https://api.github.com/repos/octocat/Hello-World/git/blobs/95b966ae1c166bd92f8ae7d1c313e738c731dfc3",
"html": "https://github.com/octocat/Hello-World/blob/master/notes/hello.txt"
}
},
"commit": {
"sha": "7638417db6d59f3c431d3e1f261cc637155684cd",
"node_id": "MDY6Q29tbWl0NzYzODQxN2RiNmQ1OWYzYzQzMWQzZTFmMjYxY2M2MzcxNTU2ODRjZA==",
"url": "https://api.github.com/repos/octocat/Hello-World/git/commits/7638417db6d59f3c431d3e1f261cc637155684cd",
"html_url": "https://github.com/octocat/Hello-World/git/commit/7638417db6d59f3c431d3e1f261cc637155684cd",
"author": {
"date": "2014-11-07T22:01:45Z",
"name": "Monalisa Octocat",
"email": "octocat@github.com"
},
"committer": {
"date": "2014-11-07T22:01:45Z",
"name": "Monalisa Octocat",
"email": "octocat@github.com"
},
"message": "my commit message",
"tree": {
"url": "https://api.github.com/repos/octocat/Hello-World/git/trees/691272480426f78a0138979dd3ce63b77f706feb",
"sha": "691272480426f78a0138979dd3ce63b77f706feb"
},
"parents": [
{
"url": "https://api.github.com/repos/octocat/Hello-World/git/commits/1acc419d4d6a9ce985db7be48c6349a0475975b5",
"html_url": "https://github.com/octocat/Hello-World/git/commit/1acc419d4d6a9ce985db7be48c6349a0475975b5",
"sha": "1acc419d4d6a9ce985db7be48c6349a0475975b5"
}
],
"verification": {
"verified": false,
"reason": "unsigned",
"signature": null,
"payload": null
}
}
}
Delete a file
Deletes a file in a repository.
You can provide an additional committer
parameter, which is an object containing information about the committer. Or, you can provide an author
parameter, which is an object containing information about the author.
The author
section is optional and is filled in with the committer
information if omitted. If the committer
information is omitted, the authenticated user's information is used.
You must provide values for both name
and email
, whether you choose to use author
or committer
. Otherwise, you'll receive a 422
status code.
Parámetros
Encabezados | ||||||
---|---|---|---|---|---|---|
Nombre, Tipo, Descripción | ||||||
accept stringSetting to | ||||||
Parámetros de ruta | ||||||
Nombre, Tipo, Descripción | ||||||
owner stringRequeridoThe account owner of the repository. The name is not case sensitive. | ||||||
repo stringRequeridoThe name of the repository. The name is not case sensitive. | ||||||
path stringRequeridopath parameter | ||||||
Parámetros de cuerpo | ||||||
Nombre, Tipo, Descripción | ||||||
message stringRequeridoThe commit message. | ||||||
sha stringRequeridoThe blob SHA of the file being replaced. | ||||||
branch stringThe branch name. Default: the repository’s default branch (usually | ||||||
committer objectobject containing information about the committer. | ||||||
Properties of the |
Nombre, Tipo, Descripción |
---|
name stringThe name of the author (or committer) of the commit |
email stringThe email of the author (or committer) of the commit |
author
objectobject containing information about the author.
Properties of theauthor
object
Nombre, Tipo, Descripción |
---|
name stringThe name of the author (or committer) of the commit |
email stringThe email of the author (or committer) of the commit |
Códigos de estado de respuesta HTTP
Código de estado | Descripción |
---|---|
200 | OK |
404 | Resource not found |
409 | Conflict |
422 | Validation failed |
503 | Service unavailable |
Ejemplos de código
curl \
-X DELETE \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: token <TOKEN>" \
http(s)://HOSTNAME/api/v3/repos/OWNER/REPO/contents/PATH \
-d '{"message":"my commit message","committer":{"name":"Monalisa Octocat","email":"octocat@github.com"},"sha":"329688480d39049927147c162b9d2deaf885005f"}'
Response
Status: 200
{
"content": null,
"commit": {
"sha": "7638417db6d59f3c431d3e1f261cc637155684cd",
"node_id": "MDY6Q29tbWl0NzYzODQxN2RiNmQ1OWYzYzQzMWQzZTFmMjYxY2M2MzcxNTU2ODRjZA==",
"url": "https://api.github.com/repos/octocat/Hello-World/git/commits/7638417db6d59f3c431d3e1f261cc637155684cd",
"html_url": "https://github.com/octocat/Hello-World/git/commit/7638417db6d59f3c431d3e1f261cc637155684cd",
"author": {
"date": "2014-11-07T22:01:45Z",
"name": "Monalisa Octocat",
"email": "octocat@github.com"
},
"committer": {
"date": "2014-11-07T22:01:45Z",
"name": "Monalisa Octocat",
"email": "octocat@github.com"
},
"message": "my commit message",
"tree": {
"url": "https://api.github.com/repos/octocat/Hello-World/git/trees/691272480426f78a0138979dd3ce63b77f706feb",
"sha": "691272480426f78a0138979dd3ce63b77f706feb"
},
"parents": [
{
"url": "https://api.github.com/repos/octocat/Hello-World/git/commits/1acc419d4d6a9ce985db7be48c6349a0475975b5",
"html_url": "https://github.com/octocat/Hello-World/git/commit/1acc419d4d6a9ce985db7be48c6349a0475975b5",
"sha": "1acc419d4d6a9ce985db7be48c6349a0475975b5"
}
],
"verification": {
"verified": false,
"reason": "unsigned",
"signature": null,
"payload": null
}
}
}
Get a repository README
Gets the preferred README for a repository.
READMEs support custom media types for retrieving the raw content or rendered HTML.
Parámetros
Encabezados |
---|
Nombre, Tipo, Descripción |
accept stringSetting to |
Parámetros de ruta |
Nombre, Tipo, Descripción |
owner stringRequeridoThe account owner of the repository. The name is not case sensitive. |
repo stringRequeridoThe name of the repository. The name is not case sensitive. |
Parámetros de consulta |
Nombre, Tipo, Descripción |
ref stringThe name of the commit/branch/tag. Default: the repository’s default branch (usually |
Códigos de estado de respuesta HTTP
Código de estado | Descripción |
---|---|
200 | OK |
404 | Resource not found |
422 | Validation failed |
Ejemplos de código
curl \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: token <TOKEN>" \
http(s)://HOSTNAME/api/v3/repos/OWNER/REPO/readme
Response
Status: 200
{
"type": "file",
"encoding": "base64",
"size": 5362,
"name": "README.md",
"path": "README.md",
"content": "encoded content ...",
"sha": "3d21ec53a331a6f037a91c368710b99387d012c1",
"url": "https://api.github.com/repos/octokit/octokit.rb/contents/README.md",
"git_url": "https://api.github.com/repos/octokit/octokit.rb/git/blobs/3d21ec53a331a6f037a91c368710b99387d012c1",
"html_url": "https://github.com/octokit/octokit.rb/blob/master/README.md",
"download_url": "https://raw.githubusercontent.com/octokit/octokit.rb/master/README.md",
"_links": {
"git": "https://api.github.com/repos/octokit/octokit.rb/git/blobs/3d21ec53a331a6f037a91c368710b99387d012c1",
"self": "https://api.github.com/repos/octokit/octokit.rb/contents/README.md",
"html": "https://github.com/octokit/octokit.rb/blob/master/README.md"
}
}
Get a repository README for a directory
Gets the README from a repository directory.
READMEs support custom media types for retrieving the raw content or rendered HTML.
Parámetros
Encabezados |
---|
Nombre, Tipo, Descripción |
accept stringSetting to |
Parámetros de ruta |
Nombre, Tipo, Descripción |
owner stringRequeridoThe account owner of the repository. The name is not case sensitive. |
repo stringRequeridoThe name of the repository. The name is not case sensitive. |
dir stringRequeridoThe alternate path to look for a README file |
Parámetros de consulta |
Nombre, Tipo, Descripción |
ref stringThe name of the commit/branch/tag. Default: the repository’s default branch (usually |
Códigos de estado de respuesta HTTP
Código de estado | Descripción |
---|---|
200 | OK |
404 | Resource not found |
422 | Validation failed |
Ejemplos de código
curl \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: token <TOKEN>" \
http(s)://HOSTNAME/api/v3/repos/OWNER/REPO/readme/DIR
Response
Status: 200
{
"type": "file",
"encoding": "base64",
"size": 5362,
"name": "README.md",
"path": "README.md",
"content": "encoded content ...",
"sha": "3d21ec53a331a6f037a91c368710b99387d012c1",
"url": "https://api.github.com/repos/octokit/octokit.rb/contents/README.md",
"git_url": "https://api.github.com/repos/octokit/octokit.rb/git/blobs/3d21ec53a331a6f037a91c368710b99387d012c1",
"html_url": "https://github.com/octokit/octokit.rb/blob/master/README.md",
"download_url": "https://raw.githubusercontent.com/octokit/octokit.rb/master/README.md",
"_links": {
"git": "https://api.github.com/repos/octokit/octokit.rb/git/blobs/3d21ec53a331a6f037a91c368710b99387d012c1",
"self": "https://api.github.com/repos/octokit/octokit.rb/contents/README.md",
"html": "https://github.com/octokit/octokit.rb/blob/master/README.md"
}
}
Download a repository archive (tar)
Gets a redirect URL to download a tar archive for a repository. If you omit :ref
, the repository’s default branch (usually
master
) will be used. Please make sure your HTTP framework is configured to follow redirects or you will need to use
the Location
header to make a second GET
request.
Note: For private repositories, these links are temporary and expire after five minutes.
Parámetros
Encabezados |
---|
Nombre, Tipo, Descripción |
accept stringSetting to |
Parámetros de ruta |
Nombre, Tipo, Descripción |
owner stringRequeridoThe account owner of the repository. The name is not case sensitive. |
repo stringRequeridoThe name of the repository. The name is not case sensitive. |
ref stringRequerido |
Códigos de estado de respuesta HTTP
Código de estado | Descripción |
---|---|
302 | Found |
Ejemplos de código
curl \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: token <TOKEN>" \
http(s)://HOSTNAME/api/v3/repos/OWNER/REPO/tarball/REF
Response
Status: 302
Download a repository archive (zip)
Gets a redirect URL to download a zip archive for a repository. If you omit :ref
, the repository’s default branch (usually
master
) will be used. Please make sure your HTTP framework is configured to follow redirects or you will need to use
the Location
header to make a second GET
request.
Note: For private repositories, these links are temporary and expire after five minutes.
Parámetros
Encabezados |
---|
Nombre, Tipo, Descripción |
accept stringSetting to |
Parámetros de ruta |
Nombre, Tipo, Descripción |
owner stringRequeridoThe account owner of the repository. The name is not case sensitive. |
repo stringRequeridoThe name of the repository. The name is not case sensitive. |
ref stringRequerido |
Códigos de estado de respuesta HTTP
Código de estado | Descripción |
---|---|
302 | Found |
Ejemplos de código
curl \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: token <TOKEN>" \
http(s)://HOSTNAME/api/v3/repos/OWNER/REPO/zipball/REF
Response
Status: 302