Skip to main content
The REST API is now versioned. For more information, see "About API versioning."

Gitignore

使用 REST API 获取可用于忽略文件和目录的 .gitignore 模板。

关于 gitignore

通过 API 在 GitHub.com 上创建新存储库时,可以指定一个 .gitignore 模板在创建后应用于存储库。 可以使用 REST API 从 GitHub .gitignore 存储库中获取 .gitignore 模板。

获取 gitignore 模板时,你可以使用 application/vnd.github.raw 自定义媒体类型。 有关详细信息,请参阅“媒体类型”。

Get all gitignore templates

Works with GitHub Apps

List all templates available to pass as an option when creating a repository.

HTTP response status codes for "Get all gitignore templates"

Status codeDescription
200

OK

304

Not modified

Code samples for "Get all gitignore templates"

get/gitignore/templates
curl -L \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2022-11-28" \ https://api.github.com/gitignore/templates

Response

Status: 200
[ "Actionscript", "Android", "AppceleratorTitanium", "Autotools", "Bancha", "C", "C++" ]

Get a gitignore template

Works with GitHub Apps

The API also allows fetching the source of a single template. Use the raw media type to get the raw contents.

Parameters for "Get a gitignore template"

标头
名称, 类型, 说明
accept string

Setting to application/vnd.github+json is recommended.

路径参数
名称, 类型, 说明
name string 必须

HTTP response status codes for "Get a gitignore template"

Status codeDescription
200

OK

304

Not modified

Code samples for "Get a gitignore template"

get/gitignore/templates/{name}
curl -L \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2022-11-28" \ https://api.github.com/gitignore/templates/NAME

Response

Status: 200
{ "name": "C", "source": "# Object files\n*.o\n\n# Libraries\n*.lib\n*.a\n\n# Shared objects (inc. Windows DLLs)\n*.dll\n*.so\n*.so.*\n*.dylib\n\n# Executables\n*.exe\n*.out\n*.app\n" }